URL clash between FlatPages causes middleware error
|Reported by:||emes||Owned by:|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||yes|
Steps to reproduce:
- Install flatpages app, as described in the documentation.
- Create flatpage with URL /bar/ and assign it to site foo.
- Create another flatpage with URL /bar/ and also assign it to site foo.
- Go to http://foo/bar/
It looks FUBAR, I mean 500. This is not a good way to handle it, even if admins receive an email about exception. Why?
Usually content editors are not admins. After adding such page, they can only guess what happened and why the content doesn't appear.
The attached patch fixes it. It does two things:
- Validates flatpage when saved through admin panel. If there is an URL clash for some of the sites, validation errors are generated for 'sites' field.
- For installations where a clash has already occured and is present in the database, it just serves the first page found by query. It may be misleading to hide the error, but I assume that (i) it's better to serve content than 500 to end user and (ii) any doubt would eventually cause content editor to go to the admin panel and try to edit the page, running the new validation.
Change History (13)
Changed 5 years ago by emes
comment:1 Changed 5 years ago by russellm
- Has patch set
- milestone set to 1.2
- Needs documentation unset
- Needs tests set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted
Changed 5 years ago by ryazwinski
comment:8 Changed 4 years ago by gabrielhurley
- Component changed from Contrib apps to contrib.flatpages