Skip to content

Commit 9c6628b

Browse files
committed
[fix] Fixes by @coderabbitai
1 parent 8bec3c4 commit 9c6628b

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

openwisp_users/management/commands/export_users.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,6 @@ def _get_field_value(self, user, field):
170170
self._normalize_value(self._get_nested_attr(attr, f)) for f in subfields
171171
)
172172
val = self._get_nested_attr(user, name)
173+
if isinstance(val, (QuerySet, BaseManager)):
174+
return ""
173175
return self._normalize_value(val)

openwisp_users/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

1818
def _export_organizations(user):
19+
# _export_organizations reads user.organizations_dict which is populated
20+
# when the user is added to the organization.
1921
return ",".join(
2022
f'({org_id},{perm["is_admin"]})'
2123
for org_id, perm in user.organizations_dict.items()

openwisp_users/tests/test_commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _broken_callable(user):
191191
):
192192
# the command wraps callable errors in CommandError with callable name
193193
call_command("export_users", filename=self.temp_file.name, stderr=stderr)
194-
self.assertIn("Error calling function '", str(context.exception) or "")
194+
self.assertIn("Error calling function '", str(context.exception))
195195

196196
@patch.object(
197197
app_settings,
@@ -265,3 +265,10 @@ class FakeUser:
265265

266266
result = Command()._get_field_value(FakeUser(), "intermediate.sub_field")
267267
self.assertEqual(result, "")
268+
269+
def test_plain_relation_field_returns_empty_string(self):
270+
org = self._create_org(name="org1")
271+
user = self._create_user()
272+
self._create_org_user(organization=org, user=user, is_admin=True)
273+
result = Command()._get_field_value(user, "openwisp_users_organizationuser")
274+
self.assertEqual(result, "")

0 commit comments

Comments
 (0)