-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Fixed #30172 -- Prevented Meta constraints from being removed in other migration operations. #10978
Fixed #30172 -- Prevented Meta constraints from being removed in other migration operations. #10978
Conversation
9471a3a
to
c2a73ec
Compare
issue still actual for unique constraints for sqlite, that related to sqlite introspection bug: https://code.djangoproject.com/ticket/30183 |
c2a73ec
to
a728d46
Compare
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.
fix the flake8 error plz
a728d46
to
23a85b1
Compare
fixed |
23a85b1
to
d062194
Compare
Is #11005 no longer a dependency of this? |
Oracle errors:
|
d062194
to
c07b4e6
Compare
Yep, removed
Look like oracle doesn't have issue that solve this MR for another databases because it forbid same field constraints creation on database level. So one of approaches can be to skip this tests for oracle. Another side: for me oracle behavior looks logical and another way to solve issue can be forbid to create/change model with same fields constraints (if you didn't create it yet). However this two approaches quite separate and can be done with different tickets, what do you think? |
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.
I'm okay with skipping the test on Oracle.
tests/schema/tests.py
Outdated
|
||
# Drop the check constraint | ||
with connection.schema_editor() as editor: | ||
AuthorWithUniqueName._meta.constraints = [] # sqlite hack |
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.
I think we'd want more details about why this hack is needed.
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.
Isn't the AuthorWithUniqueName
an error? Shouldn't it be Author
in this test? (The similar lines in the other tests use the model adjusted in that test.)
But if so, it's not causing a failure on SQLite, so what's it for?
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.
added details
chaged AuthorWithUniqueName
to Author
, it doesn't raise because remove_constraint
for sqlite use model._meta.constraints
when recreate table and just had incorrect state in database after test run
tests/schema/tests.py
Outdated
# Ensure the constraints exist | ||
constraints = self.get_constraints(Author._meta.db_table) | ||
self.assertIn(custom_constraint_name, constraints) | ||
self.assertEqual( |
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.
This would be more readable and consistent with our indentation style with something like:
foo_constraints = [
name for name, details in constraints.items()
if details['columns'] == ['name'] and details['unique'] and name != custom_constraint_name]
]
self.assertEqual(len(foo_constraints), 1)
(choosing a different name than "foo"
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.
changed
tests/schema/tests.py
Outdated
# Create table | ||
with connection.schema_editor() as editor: | ||
editor.create_model(AuthorWithUniqueName) | ||
|
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.
You can omit the blank line before each comment.
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.
removed
tests/schema/tests.py
Outdated
|
||
# Drop the check constraint | ||
with connection.schema_editor() as editor: | ||
AuthorWithUniqueName._meta.constraints = [] # sqlite hack |
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.
Isn't the AuthorWithUniqueName
an error? Shouldn't it be Author
in this test? (The similar lines in the other tests use the model adjusted in that test.)
But if so, it's not causing a failure on SQLite, so what's it for?
tests/schema/tests.py
Outdated
@@ -1671,6 +1731,60 @@ class Meta: | |||
with self.assertRaises(IntegrityError): | |||
Tag.objects.create(title='bar', slug='foo') | |||
|
|||
def test_remove_field_uniqueness_does_not_remove_custom_constraints(self): |
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.
test_removing_field_constraint_does_not_remove_meta_constraint
? (Similar for other tests?)
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.
sorry, look like I miss point of you questions, by the way all tests in PR pretty similar
tests/schema/tests.py
Outdated
constraint = CheckConstraint(check=Q(height__gte=0), name='author_height_gte_0_check') | ||
custom_constraint_name = constraint.name | ||
|
||
try: |
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.
Question: the try...finally...
is just to ensure test isolation yes?
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.
yep, looks it unnecessary when state cleaned with last lines of test, so just removed it
c07b4e6
to
d9be31f
Compare
added |
d9be31f
to
293e8c0
Compare
…t from removing Meta constraints.
…r from removing Meta constraints/indexes.
293e8c0
to
5c17c27
Compare
Thanks for hardwork here @tbicr and @timgraham. |
https://code.djangoproject.com/ticket/30172