Address permissions not maintained correctly #1363

Closed
opened 2025-09-23 20:46:58 +02:00 by magicfelix · 11 comments
Member

Observed for the permissions core.view_address / core.view_addresses.

Before the Address model existed, core.view_address was an extra permission on Person. Now it is called core.view_addresses, and core.view_address is the default Django permission for the Address model.

Problem: Permission.objects.filter(content_type__app_label="core", codename="view_address") does return 2 results, which should not be the case. Permission.objects.filter(content_type__app_label="core", codename="view_addresses") does not return any result, unless I use makemigrations to create a migration that alters the model options and migrate, which creates the Permission.

Possible solutions:

  • Migration that renames the old core.view_address into core.view_addresses
  • …?
Observed for the permissions `core.view_address` / `core.view_addresses`. Before the `Address` model existed, `core.view_address` was an extra permission on `Person`. Now it is called `core.view_addresses`, and `core.view_address` is the default Django permission for the `Address` model. Problem: `Permission.objects.filter(content_type__app_label="core", codename="view_address")` does return 2 results, which should not be the case. `Permission.objects.filter(content_type__app_label="core", codename="view_addresses")` does not return any result, unless I use `makemigrations` to create a migration that alters the model options and `migrate`, which creates the `Permission`. Possible solutions: * Migration that renames the old `core.view_address` into `core.view_addresses` * …?
Owner

So, the migration should exist (generally speaking shouldn't makemigrations change anything). See !3510 for reference. Of the course, the old permission shouldn't exist anymore.

So, the migration should exist (generally speaking shouldn't `makemigrations` change anything). See !3510 for reference. Of the course, the old permission shouldn't exist anymore.
Owner

assigned to @hansegucker

assigned to @hansegucker
Owner

Will do this with the general overhaul of address editing.

Will do this with the general overhaul of address editing.
Owner

changed title from Permissions not maintained correctly to Address permissions not maintained correctly

<p>changed title from <code class="idiff"><span class="idiff left right deletion">P</span>ermissions not maintained correctly</code> to <code class="idiff"><span class="idiff left right addition">Address p</span>ermissions not maintained correctly</code></p>
Owner

mentioned in merge request !3603

mentioned in merge request !3603
Owner

mentioned in commit bbb48f874d

mentioned in commit bbb48f874d7f40b5078203d53c94070835fbffc8
Author
Member

Permission.objects.filter(content_type__app_label="core", codename="view_address") still returnes 2 results.

`Permission.objects.filter(content_type__app_label="core", codename="view_address")` still returnes 2 results.
Author
Member
│   File "/usr/local/lib/python3.13/dist-packages/django/core/handlers/base.py", line 197, in _get_response                                                                                        │
│     response = wrapped_callback(request, *callback_args, **callback_kwargs)                                                                                                                      │
│   File "/usr/lib/python3.13/contextlib.py", line 85, in inner                                                                                                                                    │
│     return func(*args, **kwds)                                                                                                                                                                   │
│   File "/usr/lib/python3.13/contextlib.py", line 85, in inner                                                                                                                                    │
│     return func(*args, **kwds)                                                                                                                                                                   │
│   File "/usr/local/lib/python3.13/dist-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper                                                                                      │
│     return view_func(request, *args, **kwargs)                                                                                                                                                   │
│   File "/usr/local/lib/python3.13/dist-packages/django/views/generic/base.py", line 105, in view                                                                                                 │
│     return self.dispatch(request, *args, **kwargs)                                                                                                                                               │
│            ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                               │
│   File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 48, in _wrapper                                                                                                │
│     return bound_method(*args, **kwargs)                                                                                                                                                         │
│   File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 192, in _view_wrapper                                                                                          │
│     result = _process_exception(request, e)                                                                                                                                                      │
│   File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 190, in _view_wrapper                                                                                          │
│     response = view_func(request, *args, **kwargs)                                                                                                                                               │
│   File "/usr/local/lib/python3.13/dist-packages/graphene_django/views.py", line 201, in dispatch                                                                                                 │
│     result, status_code = self.get_response(request, data, show_graphiql)                                                                                                                        │
│                           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                        │
│   File "/usr/local/lib/python3.13/dist-packages/graphene_django/views.py", line 218, in get_response                                                                                             │
│     execution_result = self.execute_graphql_request(                                                                                                                                             │
│         request, data, query, variables, operation_name, show_graphiql                                                                                                                           │
│     )                                                                                                                                                                                            │
│   File "/usr/local/lib/python3.13/dist-packages/aleksis/core/views.py", line 431, in execute_graphql_request                                                                                     │
│     raise error                                                                                                                                                                                  │
│   File "/usr/local/lib/python3.13/dist-packages/graphql/execution/execute.py", line 523, in execute_field                                                                                        │
│     result = resolve_fn(source, info, **args)                                                                                                                                                    │
│   File "/usr/local/lib/python3.13/dist-packages/aleksis/core/schema/person.py", line 253, in resolve_addresses                                                                                   │
│     get_objects_for_user(info.context.user, "core.view_address", root.addresses.all()), info                                                                                                     │
│     ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                           │
│   File "/usr/local/lib/python3.13/dist-packages/guardian/shortcuts.py", line 515, in get_objects_for_user                                                                                        │
│     new_ctype = ContentType.objects.get(app_label=app_label,                                                                                                                                     │
│                                         permission__codename=codename)                                                                                                                           │
│   File "/usr/local/lib/python3.13/dist-packages/django/db/models/manager.py", line 87, in manager_method                                                                                         │
│     return getattr(self.get_queryset(), name)(*args, **kwargs)                                                                                                                                   │
│            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^                                                                                                                                   │
│   File "/usr/local/lib/python3.13/dist-packages/django/db/models/query.py", line 638, in get                                                                                                     │
│     raise self.model.MultipleObjectsReturned(                                                                                                                                                    │
│     ...<5 lines>...                                                                                                                                                                              │
│     )                                                                                                                                                                                            │
│ graphql.error.graphql_error.GraphQLError: get() returned more than one ContentType -- it returned 2!                                                                                             │
│                                                                                                                                                                                                  │
│ GraphQL request:23:3                                                                                                                                                                             │
│ 22 |   sex                                                                                                                                                                                       │
│ 23 |   addresses {                                                                                                                                                                               │
│    |   ^                                                                                                                                                                                         │
│ 24 |     id
``` │ File "/usr/local/lib/python3.13/dist-packages/django/core/handlers/base.py", line 197, in _get_response │ │ response = wrapped_callback(request, *callback_args, **callback_kwargs) │ │ File "/usr/lib/python3.13/contextlib.py", line 85, in inner │ │ return func(*args, **kwds) │ │ File "/usr/lib/python3.13/contextlib.py", line 85, in inner │ │ return func(*args, **kwds) │ │ File "/usr/local/lib/python3.13/dist-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper │ │ return view_func(request, *args, **kwargs) │ │ File "/usr/local/lib/python3.13/dist-packages/django/views/generic/base.py", line 105, in view │ │ return self.dispatch(request, *args, **kwargs) │ │ ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ │ │ File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 48, in _wrapper │ │ return bound_method(*args, **kwargs) │ │ File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 192, in _view_wrapper │ │ result = _process_exception(request, e) │ │ File "/usr/local/lib/python3.13/dist-packages/django/utils/decorators.py", line 190, in _view_wrapper │ │ response = view_func(request, *args, **kwargs) │ │ File "/usr/local/lib/python3.13/dist-packages/graphene_django/views.py", line 201, in dispatch │ │ result, status_code = self.get_response(request, data, show_graphiql) │ │ ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ │ File "/usr/local/lib/python3.13/dist-packages/graphene_django/views.py", line 218, in get_response │ │ execution_result = self.execute_graphql_request( │ │ request, data, query, variables, operation_name, show_graphiql │ │ ) │ │ File "/usr/local/lib/python3.13/dist-packages/aleksis/core/views.py", line 431, in execute_graphql_request │ │ raise error │ │ File "/usr/local/lib/python3.13/dist-packages/graphql/execution/execute.py", line 523, in execute_field │ │ result = resolve_fn(source, info, **args) │ │ File "/usr/local/lib/python3.13/dist-packages/aleksis/core/schema/person.py", line 253, in resolve_addresses │ │ get_objects_for_user(info.context.user, "core.view_address", root.addresses.all()), info │ │ ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ │ File "/usr/local/lib/python3.13/dist-packages/guardian/shortcuts.py", line 515, in get_objects_for_user │ │ new_ctype = ContentType.objects.get(app_label=app_label, │ │ permission__codename=codename) │ │ File "/usr/local/lib/python3.13/dist-packages/django/db/models/manager.py", line 87, in manager_method │ │ return getattr(self.get_queryset(), name)(*args, **kwargs) │ │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ │ │ File "/usr/local/lib/python3.13/dist-packages/django/db/models/query.py", line 638, in get │ │ raise self.model.MultipleObjectsReturned( │ │ ...<5 lines>... │ │ ) │ │ graphql.error.graphql_error.GraphQLError: get() returned more than one ContentType -- it returned 2! │ │ │ │ GraphQL request:23:3 │ │ 22 | sex │ │ 23 | addresses { │ │ | ^ │ │ 24 | id ```
Owner

created branch 1363-address-permissions-not-maintained-correctly to address this issue

created branch [`1363-address-permissions-not-maintained-correctly`](/AlekSIS/official/AlekSIS-Core/-/compare/master...1363-address-permissions-not-maintained-correctly) to address this issue
Owner

mentioned in merge request !3724

mentioned in merge request !3724
Owner

mentioned in commit 056926b03d

mentioned in commit 056926b03d792a8a65ff9116b89c7c8716add2b6
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aleksis/AlekSIS-Core#1363
No description provided.