Skip to content

Fix UniqueTogetherValidator to use instance values for unsubmitted fields on update - #10082

Open
Danish-kh-IT wants to merge 1 commit into
encode:mainfrom
Danish-kh-IT:fix/7489-unique-together-default
Open

Danish-kh-IT wants to merge 1 commit into
encode:mainfrom
Danish-kh-IT:fix/7489-unique-together-default

Conversation

@Danish-kh-IT

Copy link
Copy Markdown

Fixes #7489.

Problem

On a full (non-partial) update, UniqueTogetherValidator validated fields that were not submitted using the model field's default value, because the serializer substitutes defaults for missing fields in attrs. 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 from serializer.initial_data, not only when it is missing from attrs. Unprovided fields on an update are filled from the existing instance, as the method's comment already described. Serializers that were never given data (no initial_data) keep the previous behaviour.

Tests

Added the regression test from #7490 (Issue7489Test in tests/test_model_serializer.py), which failed before this change and passes after it. Full test suite: 1658 passed, 10 skipped.

@auvipy
auvipy self-requested a review October 22, 2026 10:14
@auvipy auvipy added this to the 3.19 milestone Oct 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Unique together validation fails with default value

2 participants