-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Skip unnecessary unique together checking #9154
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import datetime | ||
from unittest.mock import MagicMock | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
from django.db import DataError, models | ||
|
@@ -447,6 +447,22 @@ def test_do_not_ignore_validation_for_null_fields(self): | |
serializer = NullUniquenessTogetherSerializer(data=data) | ||
assert not serializer.is_valid() | ||
|
||
def test_ignore_validation_for_unchanged_fields(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @auvipy This is a new test I added for the scenario where none of the fields in the unique-together constraint are changed. For other cases, such as when any of the field values change, they are already covered by other test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was asking for if more additional tests could be provided? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, though I believe all the cases have already been covered, I might have overlooked something. Could you suggest what types of additional tests might be needed? |
||
""" | ||
If all fields in the unique together constraint are unchanged, | ||
then the instance should skip uniqueness validation. | ||
""" | ||
instance = UniquenessTogetherModel.objects.create( | ||
race_name="Paris Marathon", position=1 | ||
) | ||
data = {"race_name": "Paris Marathon", "position": 1} | ||
serializer = UniquenessTogetherSerializer(data=data, instance=instance) | ||
with patch( | ||
"rest_framework.validators.qs_exists" | ||
) as mock: | ||
assert serializer.is_valid() | ||
assert not mock.called | ||
|
||
def test_filter_queryset_do_not_skip_existing_attribute(self): | ||
""" | ||
filter_queryset should add value from existing instance attribute | ||
|
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.
will this change have any effect on schema migrations? thanks for the patch
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi @auvipy I believe there won't be any changes to the schema or any impact on migrations.