Fix serializer method field hidden unique together (#9700)#9710
Closed
ddalex wants to merge 1 commit intoencode:masterfrom
Closed
Fix serializer method field hidden unique together (#9700)#9710ddalex wants to merge 1 commit intoencode:masterfrom
ddalex wants to merge 1 commit intoencode:masterfrom
Conversation
auvipy
requested changes
May 27, 2025
Collaborator
auvipy
left a comment
There was a problem hiding this comment.
also can you please fix the failing tests as well?
| other_field = models.CharField(max_length=100, default="default_value") | ||
|
|
||
| class Meta: | ||
| unique_together = [("name", "description")] |
Collaborator
There was a problem hiding this comment.
why not using unique constraint here?
Member
There was a problem hiding this comment.
Please tidy the diff in this file. It's clearly AI generated file (even the commit is not hiding that fact), with extra verbose comments. It should follow the style of the surrounding code
3c6b780 to
c343b69
Compare
…e_together Ensures SerializerMethodFields shadowing model fields in uniqueness constraints aren't hidden.
c343b69 to
92e755b
Compare
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.
Fix: SerializerMethodField as HiddenField in unique_together
Corrects an issue where a
SerializerMethodFieldthat shares its namewith a model field involved in a
unique_togetherconstraint (orUniqueConstraint) could be incorrectly treated as aHiddenField.This typically occurred if the underlying model field was nullable or had
a default value, and the
SerializerMethodFieldwas not being correctlyprioritized during the uniqueness metadata processing.
The
ModelSerializer.get_uniqueness_extra_kwargsmethod has been updatedto ensure that if a field name corresponding to a model field in a
uniqueness constraint is explicitly declared as a
SerializerMethodFieldon the serializer, it is not converted into a
HiddenField.A test case has been added to
tests/test_model_serializer.py(
TestSerializerMethodFieldInUniqueTogether) to verify this behavior.