fix(access): use getattr instead as attribute may exist as None

ref: #789
This commit is contained in:
2025-06-06 13:25:48 +09:30
parent bcd66fd657
commit 2e5d6d4894
2 changed files with 26 additions and 26 deletions

View File

@ -52,7 +52,7 @@ class TenancyManager(models.Manager):
user_organizations: list(str()) = []
has_tenant_field = False
if hasattr(self.model, 'organization'):
if getattr(self.model, 'organization', None) is not None:
has_tenant_field = True
@ -82,38 +82,38 @@ class TenancyManager(models.Manager):
if len(user_organizations) > 0 and not user.is_superuser:
if getattr(self.model, 'is_global', False) is True:
# if getattr(self.model, 'is_global', False) is True:
if has_tenant_field:
# if has_tenant_field:
return super().get_queryset().select_related('organization').filter(
models.Q(organization__in=user_organizations)
|
models.Q(is_global = True)
)
# return super().get_queryset().select_related('organization').filter(
# models.Q(organization__in=user_organizations)
# # |
# # models.Q(is_global = True)
# )
else:
# else:
return super().get_queryset().filter(
models.Q(organization__in=user_organizations)
|
models.Q(is_global = True)
)
# return super().get_queryset().filter(
# models.Q(organization__in=user_organizations)
# # |
# # models.Q(is_global = True)
# )
# else:
if has_tenant_field:
return super().get_queryset().select_related('organization').filter(
models.Q(organization__in=user_organizations)
)
else:
if has_tenant_field:
return super().get_queryset().select_related('organization').filter(
models.Q(organization__in=user_organizations)
)
else:
return super().get_queryset().filter(
models.Q(organization__in=user_organizations)
)
return super().get_queryset().filter(
models.Q(organization__in=user_organizations)
)
if has_tenant_field:

View File

@ -37,7 +37,7 @@ class TenancyManager(
has_tenant_field = False
if hasattr(self.model, 'organization'):
if getattr(self.model, 'organization', None) is not None:
has_tenant_field = True