Skip to content

Fix regression in unique_together validation with SerializerMethodField #9712

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kalekseev
Copy link
Contributor

@kalekseev kalekseev commented May 31, 2025

While building validator unique together fields were compared with declared field names instead of model field names

fixes #9700

closes #9710

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

looks good to me

While building validator unique together fields were compared with
declared field names instead of model field names
@kalekseev
Copy link
Contributor Author

It also possible to unify code related to get_unique_together_constraints, these two code blocks are basically the same

for unique_together, queryset, condition_fields, condition in self.get_unique_together_constraints(self.Meta.model):
# Skip if serializer does not map to all unique together sources
unique_together_and_condition_fields = set(unique_together) | set(condition_fields)
if not set(source_map).issuperset(unique_together_and_condition_fields):
continue

for unique_together_list, queryset, condition_fields, condition in self.get_unique_together_constraints(model):
unique_together_list_and_condition_fields = set(unique_together_list) | set(condition_fields)
if set(field_names).issuperset(unique_together_list_and_condition_fields):
unique_constraint_names |= unique_together_list_and_condition_fields

@auvipy
Copy link
Member

auvipy commented Jun 5, 2025

you can come with the unified code for review as well

@browniebroke browniebroke changed the title Fix unique together validation. Fix regression in unique_together validation with SerializerMethodField Jun 5, 2025
Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

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

From my perspective, I'm happy to get it merge this as is. Thanks for picking it up

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.

SerializerMethodField issue after "unique together validator" fix
3 participants