-
-
Notifications
You must be signed in to change notification settings - Fork 300
Add option to model meta class to prevent proxy models being polymorphic #676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #676 +/- ##
==========================================
+ Coverage 75.40% 75.55% +0.14%
==========================================
Files 21 21
Lines 1342 1350 +8
Branches 211 214 +3
==========================================
+ Hits 1012 1020 +8
Misses 257 257
Partials 73 73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 PR adds a new polymorphic__proxy meta option to control whether proxy models behave as traditional Django proxies (aliases) or as polymorphic proxies (distinct types). This addresses issues #376 and #390 by allowing developers to opt-in to traditional Django proxy behavior when needed.
Key Changes
- Introduced
polymorphic__proxymeta attribute that can be set toTrue(traditional Django proxy/alias) orFalse(polymorphic proxy with distinct type) - Modified the manager's queryset logic to respect the new attribute when applying
instance_offilters - Added comprehensive test coverage with multiple proxy model variants to validate the new behavior
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/polymorphic/base.py | Added metaclass logic to extract and store polymorphic__proxy from model Meta, with default based on proxy setting |
| src/polymorphic/managers.py | Changed queryset logic from checking _meta.proxy to checking _meta.polymorphic__proxy to control instance filtering |
| src/polymorphic/tests/models.py | Added 6 new test model classes demonstrating different proxy configurations and inheritance hierarchies |
| src/polymorphic/tests/test_orm.py | Added 6 new test cases to validate polymorphic proxy behavior, traditional Django proxy behavior, and type conversion scenarios |
| src/polymorphic/tests/migrations/0001_initial.py | Generated migration file for the new test models |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8bd4107 to
a8276fc
Compare
Fixes #376 #390
I need to rebase and didn't have permissions to push to the original branch for #544, so this replaces that PR.