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 #31335 -- Fixed removing composed Meta constraints/indexes on foreign keys on MySQL. #15254
Fixed #31335 -- Fixed removing composed Meta constraints/indexes on foreign keys on MySQL. #15254
Conversation
afcf204
to
49b5eff
Compare
725843a
to
7347a05
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.
tests/schema/tests.py
Outdated
with editor_with_post_cleanup('indexes') as editor: | ||
editor.add_index(Book, index) | ||
editor.remove_index(Book, index) | ||
|
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 we add test for renaming a ForeignKey
included in the composed index?
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.
Should we test that actually? As stated in the ticket, for the field renaming Django adds 3 operations to the migration file: remove an index, rename the field, add the index (back). I believe it should be at least a separate ticket, that changes behavior to one operation instead of three...
hi @felixxm, I've added two commits to the PR. |
hey @felixxm,
Do I use the correct MySQL version that matches the version on the CI server? Do you see any other reasons for the test's failure? |
CI uses MySQL 5.7 (see the wiki page). This can be an issue with caching docker images, try to remove images before switching to MySQL 5.7, e.g.
|
thanks @felixxm, that helped. At least now tests fail locally :) |
I think the PR is ready to review. The single failed test looks like an unstable one and is not related to the proposed changes. |
@felixxm did you have a chance to review the updated PR |
Hi @GeyseR, if you've accounted for all feedback to date you should uncheck "Needs tests" and "Patch needs improvement" on the ticket so that there's an indication to re-review it. Rebasing from |
509bef9
to
a82479a
Compare
@jacobtylerwalls thanks for the heads up, done |
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.
@GeyseR Thanks for updates 👍
a82479a
to
433684d
Compare
hey @felixxm, I tried to simplify the tests code, how does it look now? regarding the parts that you've mentioned as covered by other tests, you are partially right - deletion of unique/index_together was covered but by other tests from the schema/tests.py file (the deletion was partially fixed a long time ago). You can find those tests as removed in my commits, I thought that it might be a good idea to keep all the tests cases in one place |
433684d
to
e11f1b7
Compare
Many thanks 🚀 I have a week off, so I'm going to review it after the holidays (June, 13th+). |
no problem, anyway I need to fix the failed tests :) |
7114373
to
6c1d515
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.
Nice 👍
I have a few remarks here and there, but mostly questions to confirm my understanding :)
(I didn't have time to look in details at the unit tests yet)
hi @David-Wobrock, thanks for the review. After some thinking I decided to change how I check for duplicate FK index: instead of checking model's definition I check the DB table structure. It looks like is much more straightforward way and also more reliable as we can find some unmanaged manual indexes that could be enough for index deletion. After that we don't need to extract get_first_index_field_name as a helper function anymore :) |
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.
In a more subjective matter, I find the unit tests with their nested functions a bit hard to read. But since I don't have anything better to suggest at the moment, that's fine to me :)
764ee07
to
d6c1a4e
Compare
@felixxm the PR is ready to review 🙄 |
Thanks 👍
No need, I can squash with final edits. |
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.
@GeyseR Thanks for updated 👍 We're getting closer.
3cf0e73
to
7d7f784
Compare
@felixxm
these two tests are now covered by I've tried to move tests from operations tests to the schema tests, and this movement also requires adding utility code (apply_operations in particular) to the |
I was asking for keeping these two and moving new one to
I'm not sure why def test_meta_unique_constraint_with_fk(self):
with connection.schema_editor() as editor:
editor.create_model(Author)
editor.create_model(Book)
constraint = UniqueConstraint(
fields=["author", "title"], name="book_author_title_uniq"
)
Book._meta.constraints = [constraint]
with connection.schema_editor() as editor:
editor.add_constraint(Book, constraint)
constraints = self.get_constraints(Book._meta.db_table)
self.assertIn(constraint.name, constraints)
Book._meta.constraints = []
with connection.schema_editor() as editor:
editor.remove_constraint(Book, constraint)
constraints = self.get_constraints(Book._meta.db_table)
self.assertNotIn(constraint.name, constraints)
def test_meta_index_with_fk(self):
with connection.schema_editor() as editor:
editor.create_model(Author)
editor.create_model(Book)
index = Index(
fields=["author", "title"], name="book_author_title_idx"
)
Book._meta.indexes = [index]
with connection.schema_editor() as editor:
editor.add_index(Book, index)
indexes = self.get_indexes(Book._meta.db_table)
self.assertNotIn("author_id", indexes)
Book._meta.indexes = []
with connection.schema_editor() as editor:
editor.remove_index(Book, index)
indexes = self.get_indexes(Book._meta.db_table)
self.assertIn("author_id", indexes) are proper regression tests for removing |
I mean that the new tests cover the cases from these two tests, so they will be redundant as they test the same thing. Let me make one more attempt with schema tests, I'll try to return soon :) |
22c42b6
to
bb173bf
Compare
hey @felixxm, I've pushed another attempt to add tests to |
bb173bf
to
cd80e92
Compare
cd80e92
to
f530955
Compare
I rebased after ec13e80 and squashed commits. |
c7f5e5a
to
5e16b09
Compare
…exes on foreign keys on MySQL.
5e16b09
to
b731e88
Compare
@GeyseR Thanks 👍 It's ready 🚀 |
@felixxm thanks for you patience with reviewing my code 😅 |
ticket-31335