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 for 974 #1717
Fix for 974 #1717
Conversation
Hi @PetrDlouhy it might be worth you making this change on the |
7f9d31f
to
48654c4
Compare
Now I rewrote this to a cleaner solution - instead of changing Widget and Fields logic I tried to change the way the default fields are derived from Model. @matthewhegarty Thanks, I rebased against v4. |
I have got the following error with the newly written test even on pure
|
Yes, in v4 you have to add the decorator to your test:
|
Also make me think that this fix could help with #1209 |
701320f
to
1cecbc2
Compare
@PetrDlouhy I tested imports / exports with this fix in place and it seems fine. One thing I noticed is that we can remove the additional queries using I added some comments - see what you think. |
@matthewhegarty The Of course it is good idea to add |
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 clarifying.
I am happy to merge this. Would you mind updating the changelog?
I have added new entry to changelog. |
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! 💯
67f1842
into
django-import-export:release-4
attribute = field_name | ||
column_name = field_name | ||
# To solve #974 | ||
if isinstance(django_field, ForeignKey) and "__" not in column_name: | ||
attribute += "_id" | ||
widget_kwargs["key_is_id"] = True |
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.
Correct me if I am wrong, please, but to me, it feels like this belongs more in widget_kwargs_for_field
than here.
Problem
#974
Solution
This is concept of a solution of the problem with unnecessary queries for IDs.
I would like to get some feedback on this. I am not sure about which other cases could this affect and whether we are able to fix more cases.
The current solution is mostly bypassing the logic of Widget and leaking it to the Fields. But I am not sure how to make this correctly, because the data in Widgets are not sufficient for this and also when the
Widget.render()
is called the demage is already done and the query is called.Acceptance Criteria
It includes a clear test case scenario documenting the problem.