Ensure DynamicRelationField.to_representation is passed correct instance#297
Open
fdintino wants to merge 1 commit intoAltSchool:masterfrom
Open
Ensure DynamicRelationField.to_representation is passed correct instance#297fdintino wants to merge 1 commit intoAltSchool:masterfrom
fdintino wants to merge 1 commit intoAltSchool:masterfrom
Conversation
0e44af2 to
2b6b9a1
Compare
2b6b9a1 to
ac913c2
Compare
Contributor
Author
|
This PR was closed accidentally. Re-opening. |
Contributor
Author
|
Any chance this might get a review and merged? We're currently installing from our github fork, but we'd prefer to avoid that if we can. Thanks! |
|
Seconding the request for eyes on this, it would be super helpful ❤️ |
Contributor
Author
|
Let me know if there's anything I can to do to help get this merged in. We'd prefer it if we didn't need to maintain a fork. Thank you! |
Contributor
|
@suavesav can help? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a regression that was originally introduced in d0c31d3 and a869d28
There were a few places in our code where we have subclassed
DynamicRelationFieldand overriddento_representation, conditionally short-circuiting the serialization of a many to many field depending on the request, context, or a property of the parent instance. We had been relying on the fact thatto_representationfor aModelFieldand aDynamicRelationFieldwas always passed the parent instance. But in d0c31d3, and then a869d28, some of the responsibilities ofto_representationwere moved over toget_attribute.After updating to the latest version our methods no longer worked, because
to_representationwas now being passed theManyRelatedManager, not the parent instance. This seems to me like a bug, as it breaks expectations about the arguments and return values ofget_attributeandto_representation. And so far as I can tell, moving the logic back fromget_attributedoesn't break anything in dynamic-rest, since the two methods are only ever called together, e.g.: inWithDynamicSerializerMixin._faster_to_representation():I've included a test that shows roughly how we sometimes override
to_representation.