Skip to content

fix: NoReverseMatch: Reverse for 'filer_file_expand' not found error for svgs - #1619

Merged
fsbraun merged 4 commits into
masterfrom
fix/reverse
Sep 11, 2026
Merged

fsbraun merged 4 commits into
masterfrom
fix/reverse

Conversation

@fsbraun

@fsbraun fsbraun commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary by Sourcery

Support expanding SVG files regardless of whether they are stored as Image or File records.

New Features:

  • Add an admin expand view for SVG files stored as generic File records.

Bug Fixes:

  • Fix SVG admin links and directory listings to resolve against the actual file model, preventing NoReverseMatch errors.

Enhancements:

  • Move expand-view handling into the shared FileAdmin and enforce read permissions before displaying files.

Tests:

  • Add coverage for SVG expansion through FileAdmin, model-specific links, directory listings, and read-permission enforcement.

Related resources

Checklist

  • I have opened this pull request against master
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #pr-reviews on
    Discord to find a “pr review buddy” who is going to review my pull request.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fsbraun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 14 hours and 8 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Centralizes SVG expansion in the base file admin so SVGs stored as generic File records use the correct model-specific admin URL, are protected by read permissions, and are covered by change-form, view, authorization, and directory-listing tests.

Sequence diagram for SVG expansion in the file admin

sequenceDiagram
    participant AdminBrowser
    participant FileAdmin
    participant DjangoURLResolver
    participant File
    participant Permissions
    participant TemplateResponse

    AdminBrowser->>FileAdmin: render_change_form(request, context)
    FileAdmin->>DjangoURLResolver: reverse(admin_urlname(self.opts, expand), file_id)
    DjangoURLResolver-->>FileAdmin: model-specific expand URL
    FileAdmin-->>AdminBrowser: change form with expand_image_url

    AdminBrowser->>FileAdmin: expand_view(request, file_id)
    FileAdmin->>File: get_object_or_404(self.model, pk=file_id)
    File-->>FileAdmin: file
    FileAdmin->>Permissions: has_admin_read_permission(request, file)
    alt read permission granted
        FileAdmin->>TemplateResponse: TemplateResponse(request, expand.html, original_url)
        TemplateResponse-->>AdminBrowser: expanded SVG
    else read permission denied
        FileAdmin-->>AdminBrowser: Http404
    end
Loading

File-Level Changes

Change Details Files
Move SVG expansion handling into the shared file admin and generate model-specific expansion URLs.
  • Register an expand route for every file admin, including generic File records.
  • Resolve SVG links using the current admin’s model metadata instead of always targeting ImageAdmin.
  • Implement a shared expand view that loads the appropriate model, checks read permission, and renders the existing SVG template.
  • Remove the duplicate ImageAdmin-specific route and view.
filer/admin/fileadmin.py
filer/admin/imageadmin.py
Add regression coverage for generic-file SVG expansion, authorization, and directory listings.
  • Verify change forms show expansion links only for SVGs and use the correct admin route.
  • Test rendering SVGs stored as File records.
  • Test unreadable files return 404.
  • Test directory listings link generic SVG files to FileAdmin’s expand view.
tests/test_admin.py
Document the SVG admin expansion bug fix.
  • Add the fix to the project changelog.
CHANGELOG.rst

Assessment against linked issues

Issue Objective Addressed Explanation
#1590 Register a valid SVG expand URL and view for generic File records, so reversing filer_file_expand succeeds. ✅
#1590 Ensure SVG expansion links resolve against the admin/model that owns the file, including files stored as File records rather than Image records. ✅
#1590 Prevent SVG directory listings and file-picker/admin views from raising NoReverseMatch, with appropriate permission protection for the expand view. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.17%. Comparing base (d893e2d) to head (32923a5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1619      +/-   ##
==========================================
- Coverage   83.18%   83.17%   -0.01%     
==========================================
  Files          79       79              
  Lines        4003     4001       -2     
  Branches      549      550       +1     
==========================================
- Hits         3330     3328       -2     
  Misses        520      520              
  Partials      153      153              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@read-the-docs-community

read-the-docs-community Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

@fsbraun

fsbraun commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai

sourcery-ai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Sorry @fsbraun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 hour and 54 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@fsbraun

fsbraun commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. The new expand endpoint serves the file's original URL after an admin read-permission check, so an incorrect permission check could disclose files to an unauthorized user. Reverting would remove the endpoint but would not undo any exposure that already occurred.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun
fsbraun requested a review from vinitkumar September 7, 2026 08:41
@fsbraun
fsbraun merged commit f76c9cc into master Sep 11, 2026
103 checks passed
@fsbraun
fsbraun deleted the fix/reverse branch September 11, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NoReverseMatch for filer_file_expand when listing SVG files in folder view

2 participants