openwisp / openwisp-users

Implementation of user management and multi-tenancy for OpenWISP
https://openwisp.io/docs/dev/users/
BSD 3-Clause "New" or "Revised" License
163 stars 74 forks source link

[BUG] `FilterSerializerByOrgManaged` produces an error when the `organization` field is set to `read_only` #268

Closed ManishShah120 closed 3 years ago

ManishShah120 commented 3 years ago

https://github.com/openwisp/openwisp-users/blob/4bb0310eaefc75006bd802100d36a09a1fb9af9b/openwisp_users/api/mixins.py#L141-L145

When the mixin FilterSerializerByOrgManaged is used to filter the organization field in a serializer fields, if the field is set to read_only, then no queryset attribute is found in PrimaryKey, due to which it raises an AttributeError error as 'NoneType' object has no attribute 'filter'

image

We will probably need to filter the field only when it is not set to read_only.

PS: I found this issue while working on the REST API for the topology module. https://github.com/openwisp/openwisp-network-topology/pull/113

The error can be found in the CI of this build. https://github.com/openwisp/openwisp-network-topology/pull/113/checks?check_run_id=3282685073