Repository navigation
Fix UniqueTogetherValidator to use instance values for unsubmitted fields on update - #10082
Open
Danish-kh-IT wants to merge 1 commit into
Open
Danish-kh-IT wants to merge 1 commit into
Danish-kh-IT wants to merge 1 commit into
Conversation
…of instance values on update
auvipy
self-requested a review
October 22, 2026 10:14
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7489.
Problem
On a full (non-partial) update,
UniqueTogetherValidatorvalidated fields that were not submitted using the model field's default value, because the serializer substitutes defaults for missing fields inattrs. If another row already held the default combination, validation failed with a spurious "must make a unique set" error — even though the instance's actual values were unique.Fix
In
UniqueTogetherValidator.filter_queryset, a constraint field now counts as unprovided when it is absent fromserializer.initial_data, not only when it is missing fromattrs. Unprovided fields on an update are filled from the existing instance, as the method's comment already described. Serializers that were never given data (noinitial_data) keep the previous behaviour.Tests
Added the regression test from #7490 (
Issue7489Testintests/test_model_serializer.py), which failed before this change and passes after it. Full test suite: 1658 passed, 10 skipped.