-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
fix: migrate drop the wrong m2m field when model have multi m2m fields #376
Conversation
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.
Thanks for working on this! I left a few comments.
75ad00a
to
1be8903
Compare
old_m2m_fields: list[dict], new_m2m_fields: list[dict] | ||
) -> tuple[list[dict], list[dict]]: | ||
""" | ||
Reorder m2m fields to help dictdiffer.diff generate more precise changes |
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 please explain why we need to order the fields in this way? Is the code that follows this expects some sort of ordering? What are the criteria for this ordering?
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.
- why we need to order the fields in this way?
Good question~
May be a custom diff function is a better solution:
- if old_m2m_fields and new_m2m_fields:
- old_m2m_fields, new_m2m_fields = reorder_m2m_fields(
- old_m2m_fields, new_m2m_fields
- )
- for action, option, change in diff(old_m2m_fields, new_m2m_fields):
+ for action, option, change in diff_plus(old_m2m_fields, new_m2m_fields):
- Is the code that follows this expects some sort of ordering? What are the criteria for this ordering?
All cases are covered by unittest: https://github.com/tortoise/aerich/pull/376/files#diff-33c13e0b177bacd2f02e29bcb8aea5b49e7ce34901fd8f41fefb65defba1bd33R7
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.
Thanks for the reply!
I'm not saying that a custom diff function is better, I'm just trying to understand why this ordering is required. if it's really hard to explain with a spoken language, it's a good sign that something isn't right.
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.
@henadzit I updated the PR description
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.
Fixes #375
Fixes #150
Description
The two bugs are some thing like the following case:
Got:
Expected:
Reason
When use
dictdiffer.diff
to compare two lists of dicts, it just compare elements at the same position:Solution