Skip to content

SerializerMethodResourceRelatedField breaks parent chain #780

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

Closed
glowka opened this issue Apr 13, 2020 · 1 comment · Fixed by #781
Closed

SerializerMethodResourceRelatedField breaks parent chain #780

glowka opened this issue Apr 13, 2020 · 1 comment · Fixed by #781

Comments

@glowka
Copy link
Contributor

glowka commented Apr 13, 2020

If SerializerMethodResourceRelatedField is called with many=True and creates child field it misses call to bind() which would complete setting the relation between parent field and child field.

In effect it breaks the pattern that on every DRF field you can always go up the tree towards the root using parent attribute.

That part of ManyRelatedField.init() is missing:

class ManyRelatedField:
    ...
    def __init__(self, child_relation=None, *args, **kwargs):
        self.child_relation = child_relation
        ...
        self.child_relation.bind(field_name='', parent=self)

I am aware that there are some issues related to SerializerMethodResourceRelatedField already reported in #639, but since this bug is completely independent thing, I report it as separate issue.

@sliverc
Copy link
Member

sliverc commented Apr 14, 2020

Thanks for the hinter. I agree this is not directly related to #639 and would be an easier fix.

PR is also welcome for whoever want to pick this up.

glowka added a commit to glowka/django-rest-framework-json-api that referenced this issue Apr 15, 2020
glowka added a commit to glowka/django-rest-framework-json-api that referenced this issue Apr 15, 2020
glowka added a commit to glowka/django-rest-framework-json-api that referenced this issue Apr 22, 2020
sliverc pushed a commit that referenced this issue May 3, 2020
Fixes #639 - interface not consistent with `SerializerMethodField`
Fixes #779 - no enforcement of `read_only`
Fixes #780 - broken `parent` chain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants