Fix related resource on inherited polymorphic model #767
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.
Fixes #621
Description of the Change
When adding a
ResourceRelatedField
to a serializer that is included in thepolymorphic_serializers
list of a polymorphic serializer, the
parent_model
is not correctly resolved inget_related_resource_type
: instead of resolving to the inherited type, the base type is resolved. This can cause anAttributeError
if the field in question is not present on the base model.We ran into this, and then found the closed and seemingly abandoned issue referenced above. This PR implements the fix suggested by the original author, who deserves all the credit. The example code has been expanded to trigger the error when running the test-suite.
Thanks in advance for your time and please let us know if you have any suggestions for improvement.
Checklist
unit-test addedtest-suite failure is introduced, but no unit-test addeddocumentation updatedunnecessaryCHANGELOG.md
updated (only for user relevant changes)AUTHORS