django-restql: `fields` kwarg conflicts with a FK NestedField with `accept_pk` kwarg when updating
I’m running into an issue when PATCHing or PUTing a resource with a nested serializer. For brevity, here’s an example:
class EmployeeJobDetailSerializer(DynamicFieldsMixin, NestedModelSerializer):
employee = NestedField(
EmployeeSerializer,
accept_pk=True,
fields=['employee_id', 'first_name', 'last_name']
)
class Meta:
model = EmployeeJobDetail
fields = ...
If I’m not mistaken, accept_pk=True essentially converts the nested serializer to a PrimaryKeyRelatedField when creating/updating. However, PrimaryKeyRelatedField does not recognize the fields argument so it throws an error: TypeError: __init__() got an unexpected keyword argument 'fields'.
Is there a way to somehow ignore fields when updating with accept_pk=True? GET works perfectly and only selects the fields that I have specified for the kwarg.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (19 by maintainers)
Commits related to this issue
- :bug:Fix error raised as a result of passing kwargs which DRF serializer doesn't recognize - Fixes #169 — committed to yezyilomo/django-restql by yezyilomo 4 years ago
Yeah fixes should be published right away. am on it.
Just open an issue and explain if it’s a bug, feature suggestion or anything else. You are welcome @andis-roze