-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Add tests for unique validation for bulk creation in model serializers #6396
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
Conversation
The unique validation in model serializers only check for existing entries on the database. If the serializer is instanced with many=True and receives more than one item in the data argument having the same value for a unique field, the .is_valid() method returns True, but calling .save() will raise an IntegrityError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rebase this? also, do ou have any fix in mind?
Will do. Thanks! I looked into the model serializer classes, but couldn't decide on a good path to put the logic of calling this validation. Especially on how to add errors to the list serializer. I'd love to hear any suggestions. For now I thought of adding a note to the docs with the example I described on the related issue #6395. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great if you can re visit it
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
The unique validation in model serializers only checks for existing entries on the database. If the serializer is instanced with
many=True
and receives more than one item in the data argument having the same value for a unique field, the.is_valid()
method returnsTrue
, but calling.save()
will raise anIntegrityError
.Related to issue #6395