cms
cms copied to clipboard
"The given data was invalid" / "This URI has already been taken." when using /{id} as route
Bug description
Unable to create a new entry when collection route is set to /{id}
with the following errors:
- "The given data was invalid"
- "This URI has already been taken."
This also happens if you have a page at e.g. /members
and try to set the route to /members/{id}
.
Setting the collection to Orderable fixes it as long as max_depth
is set to 1
How to reproduce
- Start a fresh Statamic app.
- Create a new collection.
- Set the route to
/{id}
- Try to create an entry, receive error
- Set collection to "Orderable" w/ a max depth of 1
- Create an entry without error
Optionally, create a page at e.g. /testing
and set your collection to the route /testing/{id}
and receive the same errors/solutions above.
Logs
No response
Versions
Statamic 3.2.38 Solo Laravel 8.83.4 PHP 8.1.2 No addons installed
Also tested on 3.3 beta
Installation
Fresh statamic/statamic site via CLI
Additional details
For what it's worth, one downside of the workaround is that any collections that use dates are no longer sorted by date by default (at least according to the docs).
Maybe same issue as #4032 ? Since the ID doesn't exist when it tries to create, /
(Home) already exists.
Only strange thing is the max_depth: 1
workaround.
Oh, same issue!🙄 Took me 3 hours to find this... Thank you for the workaround!
I forgot all about this issue because it was working.
I believe I was on 3.3.46 and this was no longer an issue. Then I updated to 3.3.47 and it was not working again.
My guess is that #6921 "broke" it again? @jasonvarga
Related: https://github.com/statamic/cms/issues/4032
I don't think it would have been fixed since you opened the issue. The workaround also just sounds like a fluke.
The issue is like you already explained.
If you have a route like /members/{id}
and you create a new entry, the url would be /members
since there's no id at the point where it tries to validate it. There's a conflict with the other /members
entry.
I don't think it would have been fixed since you opened the issue. The workaround also just sounds like a fluke.
The issue is like you already explained.
If you have a route like
/members/{id}
and you create a new entry, the url would be/members
since there's no id at the point where it tries to validate it. There's a conflict with the other/members
entry.
My particular issue here, is that I'm generating a Title based on other fields in the entry, therefore I cannot use an automatically generated slug based on the title.
For example, the title is August 30th, 2022
based on a date
field. The slug would then be something like august-30th-2022
. If somebody creates a second entry with the same date, they won't be able to because the slug is already taken. It cannot automatically append a -2
to the slug. Because of this issue, I've been using IDs.
It was working. I don't know when or how, but it no longer works.
Ideally I'd be able to use Antlers to generate a slug, similar to how we can generate titles or routes. Then we can toggle something like "auto-increment" to append -2
or whatever.
Any workaround ideas as it currently stands? I could make the collection "manually orderable" and set the max depth to 1
like I mentioned above, but I don't really want this collection to be drag-and-drop orderable. It should be ordered by date.
I am also confronted to this problem.
I am using title_format
to generate the title and use this title and the id in the route, with a mount page.
I have just noticed that if the route is route: '/{mount}/{title}-{id}'
it does not work indeed, but as I have other collections with similar but more complicated routes using more fields variables, that DO work, I realised that if I add "whatever" before, where "whatever" does not correspond to any existing page, it works…
route: '/{mount}/{title}-{id}'
❌
route: '/{mount}/{cours}-{module}/{title}-{id}'
✅
Maybe that can help you?
It was working. I don't know when or how, but it no longer works.
Did you have an existing page, or was the url only created in the route?
I tripped on this for hours, because when testing, I deleted the actual whatever
mount page, changed the route to whatever/{id}
and it worked. So the problem is not the route, is the reference to an actual existing page/entry id in the route.
It was working. I don't know when or how, but it no longer works.
Did you have an existing page, or was the url only created in the route? I tripped on this for hours, because when testing, I deleted the actual
whatever
mount page, changed the route towhatever/{id}
and it worked. So the problem is not the route, is the reference to an actual existing page/entry id in the route.
Yeah, my understanding is that the id
variable doesn't exist until after the Entry is created, so the route is referencing whatever the path would be without the id
, and it is already taken. You deleting the mount page allows it to be created because the path is not taken.
I don't think it would have been fixed since you opened the issue. The workaround also just sounds like a fluke.
The issue is like you already explained.
If you have a route like
/members/{id}
and you create a new entry, the url would be/members
since there's no id at the point where it tries to validate it. There's a conflict with the other/members
entry.
@jasonvarga FWIW, the example in the docs at https://statamic.dev/collections#for-when-you-dont-care-about-seo doesn't work. Should we remove this from the docs until it is fixed? Is this something that can be fixed without reworking a bunch of Statamic logic? This is still a bit of an issue for me so just wondering if I should just learn to work around this.
Oh, same issue!🙄 Took me 3 hours to find this... Thank you for the workaround!
Workaround stopped working too... :(