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 #23794 - FieldDoesNotExist error in migration with deleted fields and unique_together constraint #3533
Conversation
@andrewgodwin should I also send the patch to the Trac? |
@szopu you just have to add a comment in the ticket linking to your PR (I just did it) |
Buildbot, test this please. |
return ( | ||
isinstance(operation, (operations.AlterUniqueTogether, | ||
operations.AlterIndexTogether)) and | ||
operation.name.lower() == dependency[1].lower() |
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 included the any()
call to prevent problems with RenameField
operations that that involve a field that's in an foo_together
. Turns out, the RenameField
handles the state changes itself. No need to check for it here.
As a newbie, I have no idea why the build failed... I ran the tests using the |
buildbot, test this please. |
@szopu I think the errors were related to some errors on the master branch. They aren't related to your commit, I think. |
autodetector = MigrationAutodetector(before, after) | ||
changes = autodetector._detect_changes() | ||
# Right number of migrations? | ||
self.assertEqual(len(changes['otherapp']), 1) |
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 use self.assertNumberMigrations()
, self.assertOperationTypes()
and self.assertOperationAttributes()
instead of things like self.assertEqual(first_action.__class__.__name__, "AlterUniqueTogether")
, please. Have a look through at the top of the test case on which arguments they expect and how they work. They are also heavily used all over the place in the autodetector tests. (A overall cleanup is in #3564.)
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.
Sure! But I guess I should wait with it till the PR #3564 with the refactor will be merged into master?
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.
Hehe, if you don't mind, sure :) In that case two additional comments:
- Rename the test to
test_foo_together_remove_fk
- Use
self.book_foo_together
instead ofself.book_unique
…ds and unique_together constraint
51ad12b
to
ed4f1a3
Compare
@MarkusH rebased the code to current master & rewritten the test according to you suggestions. The only problem right now is that using |
As of now Just check for them as done in https://github.com/szopu/django/blob/ticket_23794/tests/migrations/test_autodetector.py#L895-L897 |
buildbot, test this please. |
def test_foo_together_remove_fk(self): | ||
"Tests unique_together and field removal detection & ordering" | ||
# Make state | ||
before = self.make_project_state([self.author_empty, |
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'd probably keep those lines unwrapped. Maximum line length is at 119 chars.
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 accustomed to the PEP8 79 chars line limit (this is really helpful when using multiple columns for instance in Sublime Text). I know that django does not strictly follow this rule. On the other hand, the code is still readable IMO, so I would leave it as it is now.
Added release note and merged in 72729f8, thanks! |
The code in
check_dependency
is too specific. For instance theany
function foroperation.unique_together=set([])
always returnedFalse
which caused the bug to happen. This PR contains following changes:https://code.djangoproject.com/ticket/23794