Skip to content
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

Fix ModelSerializer unique_together handling for field sources #7143

Merged
merged 2 commits into from May 13, 2020

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented Jan 15, 2020

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
Copy link

tarzzz commented Feb 28, 2020

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
Copy link
Member Author

rpkilby commented Mar 3, 2020

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

@carltongibson
Copy link
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
Copy link
Member

auvipy commented Mar 4, 2020

3.12 in this month would be really great :)

@tomchristie
Copy link
Member

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

@tomchristie tomchristie merged commit 089162e into encode:master May 13, 2020
@tomchristie
Copy link
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ModelSerializer UniqueTogetherValidator is incompatible with field source
5 participants