[Django] #32837: Flatpages manipulates url before get_object_or_404 leads to error

6 views
Skip to first unread message

Django

unread,
Jun 10, 2021, 1:36:07 PM6/10/21
to django-...@googlegroups.com
#32837: Flatpages manipulates url before get_object_or_404 leads to error
-----------------------------------------+------------------------
Reporter: snake-soft | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Django flatpages has some unwanted behaviour can lead to a catched
exception that is not easy to resolve.
This problem occurs when saving a FlatPage object without a leading slash
in the url.

The view is located in:
django.contrib.flatpages.views

This is the problematic flatpage view:
{{{
def flatpage(request, url):
if not url.startswith('/'):
url = '/' + url
site_id = get_current_site(request).id
try:
f = get_object_or_404(FlatPage, url=url, sites=site_id)
except Http404:
if not url.endswith('/') and settings.APPEND_SLASH:
url += '/'
f = get_object_or_404(FlatPage, url=url, sites=site_id)
return HttpResponsePermanentRedirect('%s/' % request.path)
else:
raise
return render_flatpage(request, f)
}}}


I think it doesn't make sense to manipulate the url at this point because
nothing happens with the url between manipulating an fetching the FlatPage
from db.

--
Ticket URL: <https://code.djangoproject.com/ticket/32837>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 11, 2021, 12:39:10 AM6/11/21
to django-...@googlegroups.com
#32837: Flatpages manipulates url before get_object_or_404 leads to error
-------------------------------+--------------------------------------
Reporter: Snake-Soft | Owner: nobody

Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "Screenshot_20210611_063559.png" added.

Django

unread,
Jun 11, 2021, 12:42:12 AM6/11/21
to django-...@googlegroups.com
#32837: Flatpages manipulates url before get_object_or_404 leads to error
-----------------------------------+--------------------------------------
Reporter: Snake-Soft | Owner: nobody
Type: Bug | Status: closed
Component: contrib.flatpages | Version: 3.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid
* component: Uncategorized => contrib.flatpages


Comment:

Thanks for this ticket, however I'm not sure what you're proposing or what
kind of issue you want to report. Also URL should have a leading slash:

[[Image(Screenshot_20210611_063559.png)]]

--
Ticket URL: <https://code.djangoproject.com/ticket/32837#comment:1>

Reply all
Reply to author
Forward
0 new messages