-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix: DjangoOptimizerExtension corrupts nested objects' fields' prefetch objects #380
Fix: DjangoOptimizerExtension corrupts nested objects' fields' prefetch objects #380
Conversation
… object before invoking add_prefix
… test_single test
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 this! :)
The -1 is due to the copy vs deepcopy comment I've made. Solving it and we should be good to merge
strawberry_django/optimizer.py
Outdated
p.add_prefix(prefix) | ||
prefetch_related.append(p) | ||
# add_prefix modifies the field's prefetch object, so we copy it before | ||
p_copy = deepcopy(p) |
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.
Hrm, the only solution I can think right now would be to create a Prefetch
object by hand, but then we would need to update it in case it gets changed in django.
The only question here would be: Any reason to use deepcopy
instead of copy
? Unless I'm missing something, a copy should be enough to fix the issue here
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.
Yeah, I tried instantiating directly, creating the Prefetch
object by hand and it's also not super trivial with the internal levels
and protected variables. Kind of a messy hard-to-copy class.
I don't really have a good reason for deepcopy, fair point, I changed it to copy.copy
and the test still works :)
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #380 +/- ##
=======================================
Coverage 87.98% 87.99%
=======================================
Files 33 33
Lines 2971 2973 +2
=======================================
+ Hits 2614 2616 +2
Misses 357 357
☔ View full report in Codecov by Sentry. |
Description
This PR aims to resolve issue #379 .
I included a reproducible test and a suggested fix, where the
Prefetch
object gets deepcopied to avoid the side effects fromadd_prefix
.Considerations:
I'm also very open for improving the test case included. If you know a better way on how to do it without the custom type setup, please let me know.
Types of Changes
Issues Fixed or Closed by This PR
Checklist
I love the work you do here, thanks a lot for the really awesome work! ❤️