| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…ogether validator
- Add helper function for extracting fields from Q objects - Move test methods inside TestUniquenessTogetherValidation class - All 67 tests passing Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
This PR fixes DRF’s ModelSerializer uniqueness validation for Django UniqueConstraint objects whose condition references additional model fields, ensuring DRF uses serializer-level UniqueTogetherValidator (with condition-awareness) instead of an incorrect field-level UniqueValidator.
Changes:
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file| File | Description |
|---|---|
| rest_framework/compat.py | Adds helper to extract referenced base fields from Q conditions. |
| rest_framework/utils/field_mapping.py | Skips field-level UniqueValidator when condition references additional fields. |
| rest_framework/serializers.py | Treats certain single-field conditional UniqueConstraints as “unique-together” for serializer-level validation. |
| tests/test_validators.py | Adds/adjusts tests for conditional-field uniqueness behavior and expected validator placement. |
| docs/api-guide/validators.md | Documents how DRF handles UniqueConstraint conditions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
| ] | ||
|
|
||
|
|
||
| ## Updating nested serializers |
…eferenced_base_fields
|
I find the whole conditional uniqueness stuff confusing and don't have the conceptual clarity in my head atm to give this a solid review (I'm sorry). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is a rebased and conflict-resolved version of PR #9744.
Changes:
Resolves #9707
Supersedes #9744 (with resolved conflicts)
When using Django's UniqueConstraint with conditions that reference other fields,
DRF now correctly applies UniqueTogetherValidator instead of UniqueValidator.