-
Notifications
You must be signed in to change notification settings - Fork 299
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
Avoid query explosion for related fields where I can user pk_only_opt… #374
Avoid query explosion for related fields where I can user pk_only_opt… #374
Conversation
I tested this change in on one of my projects and it works smoothly. Thanks. It seems that in drf 3.1 |
@sliverc I have fixed the problem we had in DRF<3.2 (_readable_field property didn't exist on Serializer class) I think the change is ready to be merged |
Codecov Report
@@ Coverage Diff @@
## master #374 +/- ##
==========================================
- Coverage 92.37% 91.97% -0.41%
==========================================
Files 56 56
Lines 2887 2917 +30
==========================================
+ Hits 2667 2683 +16
- Misses 220 234 +14
Continue to review full report at Codecov.
|
I'm going to re-target this PR to |
@santiavenda2 because this is now targeting |
@mblayman done |
@@ -170,6 +170,47 @@ def get_field_names(self, declared_fields, info): | |||
fields = super(ModelSerializer, self).get_field_names(declared, info) | |||
return list(fields) + list(getattr(self.Meta, 'meta_fields', list())) | |||
|
|||
def to_representation(self, instance): |
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.
Could you explain why this is overriding to_representation
from the ModelSerializer
? It seems like DJA is likely to diverge from the DRF upstream if this method is added. Is there some extra stuff added here that you could call out?
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.
@mblayman this is returning the JSON API identifier of the object without diving down the recursive rabbit whole. It looks like an elegant solution.
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 second look, @aidanlister. I took a look at the DRF implementation and the method seems small enough that it would be hard for DJA to diverge too much from upstream.
I've reviewed the PR and we're now testing this PR internally - everything seems to be working as expected - very impressive. Next step we'd do a production release in two weeks, but I would love to have this merged before then. |
With the added input from @aidanlister, I think we've had enough eyes looking at this to declare victory. Thanks for the contribution, @santiavenda2! |
…imization.
Also, fix AutoPrefetchMixin for ReverseOneToOneDescriptors.