Closed rogertinch closed 5 years ago
Looks like this is related to turning on headlessMode
.
@tinchalamo slugs only increment if they're used in the URL I believe. So headless mode or not, if your section entries don't have URLs (or the slug isn't used as part of the url, I think) the slug won't be forced to be unique. The unique identifiers are UID and entry ID.
In talking to the Craft team this is expected behavior when using headless mode.
Craft has never cared about whether slugs themselves are unique; only that the resulting URI is unique. And when running in headless mode, or any time you have a section that doesn't have an entry URI, there's no URI to ensure uniqueness on.
This is a serious, breaking change introduced in a minor update to Craft ...
Some of us use the slugs in other environments beyond our preview targets but still want headless mode. There should at least be a config option to ensure unique uris.
@ryanpcmcquen Well, it wasn’t a breaking change; the entire concept of headless mode was introduced in 3.3, so you have to opt into the change in behavior. However it’s already been fixed in 3.4, per https://github.com/craftcms/cms/issues/4520#issuecomment-531040417.
@brandonkelly, I am running Craft 3.4.2 locally.
I can still duplicate an entry with a preview target of {uri}
or {slug}
, and the slug does not change (meaning we get dupes still). Is there something I am missing?
Craft only cares about unique URIs, not slugs. And if the URI format contains a {slug}
token, it will increment the slug as a way of finding a unique URI. So you will need to check your section’s settings and make sure you’ve given it an Entry URI Format – ideally one that contains {slug}
.
@brandonkelly, I've given it a uri format containing both {uri}
and {slug}
, only {uri}
, and only {slug}
, the results are the same every time. It still isn't bothering to increment the slug, so I am getting duplicate URIs.
Are you sure you’re looking at the Entry URI Format setting – not the preview target URL?
@brandonkelly, I did set the Entry URI (to {slug}
) as well. It was still duplicating slugs but it isn't now after forcing a project config sync (it is weird because I had already saved the entry format, but forcing the sync seems to have actually applied the change). I did also update to 3.4.3, so maybe it was something there as well.
Is there actually a scenario where duplicate slugs are desired? Seems like the default behavior should be not to duplicate slugs/URIs, rather than the inverse.
Yep, lots of cases. Craft 1.0 actually did enforce slug uniqueness, and a ton of people requested that they be allowed to create duplicates.
Nevermind, I can still reproduce the slug duplication even with the Entry URI format, here's a recording showing the behavior:
@brandonkelly, here's a screenshot of the section config as well in case I am missing something there:
Do you have the maxSlugIncrement config setting set to 0
by chance? There is a special case where when duplicating an element, URI validation errors are ignored, so perhaps that’s happening here.
I’ve been thinking that maybe it makes sense to disable all elements by default when they are duplicated via that “Duplicate” element action. This is another good reason we should probably do that.
@brandonkelly, we don't have that setting in our codebase at all, which means we should have the default of 100
.
In that case I’m a little stumped. I’m not able to reproduce that on my end. Can you send your composer.json
and composer.lock
files, and a database backup (or at least your project.yaml
file), over to support@craftcms.com, so I can try reproducing it with those?
@brandonkelly, thanks! I just sent it over.
Description
Saving a new entry with the same title as an old entry generates a duplicate slug rather than incrementing up to a new slug.
Steps to reproduce
testing
testing
Additional info