Opened 3 years ago

Closed 3 years ago

#32837 closed Bug (invalid)

Flatpages manipulates url before get_object_or_404 leads to error

Reported by: Snake-Soft Owned by: nobody
Component: contrib.flatpages Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

Screenshot_20210611_063559.png (11.0 KB ) - added by Mariusz Felisiak 3 years ago.

Download all attachments as: .zip

Change History (2)

by Mariusz Felisiak, 3 years ago

comment:1 by Mariusz Felisiak, 3 years ago

Component: Uncategorizedcontrib.flatpages
Resolution: invalid
Status: newclosed

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:


Note: See TracTickets for help on using tickets.
Back to Top