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

Most upvoted comments

No problem! Is it possible to publish the updated package to pypi? That way, I don’t have to use my local edits to the copy-and-pasted files

Yeah fixes should be published right away. am on it.

should I post a bug report if I have problem which doesn’t necessarily is a bug?

Just open an issue and explain if it’s a bug, feature suggestion or anything else. You are welcome @andis-roze