Skip to content

Fix ModelSerializer unique_together handling for field sources - #7143

Merged
lovelydinosaur merged 2 commits into
encode:masterfrom
rpkilby:uniquetogether-field-source
May 13, 2020
Merged

lovelydinosaur merged 2 commits into
encode:masterfrom
rpkilby:uniquetogether-field-source

Conversation

@rpkilby

@rpkilby rpkilby commented Jan 15, 2020

Copy link
Copy Markdown
Contributor

This fixes #7100 which was caused by related changes in #7086. Model serializers will now correctly use serializer field names that map to the field sources in unique_together. If there are multiple fields that use the same source (seems unlikely but doesn't hurt to check?), then an error is raised instead. Note that the error is raised somewhat late during validation, but that's when the validators are generated. We could create/cache them on __init__ (maybe cache fields and validators?), but that seems like a separate discussion.

Updates ModelSerializer to check for serializer fields that map to the
model field sources in the unique_together lists.
@tarzzz

tarzzz commented Feb 28, 2020

Copy link
Copy Markdown

Bump on this. I am affected as well.

When can we expect this to be merged and available in a release?

@carltongibson carltongibson added this to the 3.12 Release milestone Mar 3, 2020
@rpkilby

rpkilby commented Mar 3, 2020

Copy link
Copy Markdown
Contributor Author

@carltongibson are we planning another 3.11.x release, or straight to 3.12?

@carltongibson

Copy link
Copy Markdown
Collaborator

I'm mentally lining up a 3.12, but we can call it 3.11.1 if you like. 😀

(There's quite a few schema changes that merit an announcement post I'd say so...)

@auvipy

auvipy commented Mar 4, 2020

Copy link
Copy Markdown
Collaborator

3.12 in this month would be really great :)

@lovelydinosaur

Copy link
Copy Markdown
Member

@carltongibson Seems sensible yup - I'd happily carve out some of my working time for that.

@lovelydinosaur
lovelydinosaur merged commit 089162e into encode:master May 13, 2020
@lovelydinosaur

Copy link
Copy Markdown
Member

Fantastic stuff, @rpkilby!

@rpkilby
rpkilby deleted the uniquetogether-field-source branch May 13, 2020 17:31
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
…e#7143)

* Fix ModelSerializer unique_together field sources

Updates ModelSerializer to check for serializer fields that map to the
model field sources in the unique_together lists.

* Ensure field name ordering consistency
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.

ModelSerializer UniqueTogetherValidator is incompatible with field source

5 participants