Skip to content

Comments

fix: guard validate_unique against unsaved Release in admin add view#2940

Merged
JacobCoffee merged 1 commit intomainfrom
fix/release-file-validate-unique-unsaved
Feb 23, 2026
Merged

fix: guard validate_unique against unsaved Release in admin add view#2940
JacobCoffee merged 1 commit intomainfrom
fix/release-file-validate-unique-unsaved

Conversation

@JacobCoffee
Copy link
Member

Summary

  • Django 5.2 (deployed Feb 6 via deps: update to django 5.2 #2741) raises ValueError("Model instances passed to related filters must be saved.") when unsaved model instances are used in queryset filters
  • ReleaseFile.validate_unique() filters by release=self.release, which fails on the admin add view because the parent Release hasn't been saved yet (no PK)
  • Adding and self.release_id skips the uniqueness query for unsaved releases — safe because no conflicting records can exist for a release not yet in the database

Context

Steve Dower hit this today trying to create the "Python install manager 26.0" release via /admin/downloads/release/add/ with an inline MSIX release file that had download_button=True. Got 500 errors 3 times.

Sentry event: d05ec42eb5a44cceb69616c057186471

The validate_unique was added in #2137 (Sept 2022) and worked fine until the Django 5.2 upgrade tightened related filter validation.

Workaround (until this is deployed): create the release without release files or with download_button unchecked, save, then edit to add them.

Test plan

  • Create a new release via /admin/downloads/release/add/ with an inline release file that has download_button=True — should save successfully
  • Edit an existing release and toggle download_button — uniqueness validation should still fire correctly

🤖 Generated with Claude Code

Django 5.2 raises ValueError when unsaved model instances are passed
to related filters. The ReleaseFile.validate_unique() method filters
by release=self.release, which fails on the admin add view because
the parent Release hasn't been saved yet (no PK).

Adding a self.release_id check skips the query for unsaved releases,
which is safe since no conflicting records can exist for a release
that isn't in the database yet.

Fixes 500 error on POST /admin/downloads/release/add/ when creating
a new release with download_button enabled on inline release files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 22:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug introduced by Django 5.2 where creating a Release with inline ReleaseFiles in the admin interface would fail with a ValueError. Django 5.2 (deployed Feb 6 via #2741) added stricter validation that prevents unsaved model instances from being used in queryset filters. The ReleaseFile.validate_unique() method was filtering by release=self.release, which failed when the parent Release hadn't been saved yet during admin add operations.

Changes:

  • Added a guard condition to check self.release_id before running the uniqueness query in ReleaseFile.validate_unique()
  • This prevents the ValueError while maintaining validation for saved releases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JacobCoffee JacobCoffee merged commit 3f06040 into main Feb 23, 2026
18 checks passed
@JacobCoffee JacobCoffee deleted the fix/release-file-validate-unique-unsaved branch February 23, 2026 22:14
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.

1 participant