Project

Profile

Help

Issue #8405

pulp_container.app.registry_api.VersionView.permission_classes is a property and drf doesn't like that

Added by alikins about 2 months ago. Updated 24 days ago.

Status:
CLOSED - NOTABUG
Priority:
Normal
Assignee:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
GalaxyNG
Sprint:
Quarter:

Description

Writing a galaxy_ng management command that pokes at the views and their permission classes and ran into:

DEBUG 2021-03-15 18:15:00,405 galaxy_ng.app.management.commands.access-policy-views access-policy-views.handle:154   713 - func.cls: <class 'pulp_container.app.registry_api.VersionView'>
DEBUG 2021-03-15 18:15:00,405 galaxy_ng.app.management.commands.access-policy-views access-policy-views.handle:155   713 - func.cls.permission_classes: <property object at 0x7f3d01eaeb38>
Traceback (most recent call last):
  File "/venv/bin/pulpcore-manager", line 33, in <module>
    sys.exit(load_entry_point('pulpcore', 'console_scripts', 'pulpcore-manager')())
  File "/src/pulpcore/pulpcore/app/manage.py", line 11, in manage
    execute_from_command_line(sys.argv)
  File "/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/src/galaxy_ng/galaxy_ng/app/management/commands/access-policy-views.py", line 158, in handle
    perms = func.cls.get_permissions(func.cls)
  File "/venv/lib64/python3.6/site-packages/rest_framework/views.py", line 278, in get_permissions
    return [permission() for permission in self.permission_classes]
TypeError: 'property' object is not iterable

History

#1 Updated by ipanova@redhat.com about 2 months ago

  • Tags GalaxyNG added

#2 Updated by mdellweg about 2 months ago

Looking at those lines:

File "/src/galaxy_ng/galaxy_ng/app/management/commands/access-policy-views.py", line 158, in handle
    perms = func.cls.get_permissions(func.cls)

It looks like you are calling a object method on a class passing the class as the self parameter (which is assumed to be an instance instead).

Can you try to use:

perms = func.cls().get_permissions()

#3 Updated by alikins about 2 months ago

perms = func.cls().get_permissions()

Seems reasonable. The view introspection stuff in access-policy-view currently has some wonky/klugey bits for handling function base views, viewset classes, and viewset instances so likely needs to handle that case.

But looking at drf code, I'm not sure it expects for viewset cls.permission_classes to be a property. At least in the sense that it doesn't do that in it's own code or tests.

And the default APIView always sets permission_classes (and friends) to class scope iterables. ie,

class APIView(View):
    ...
    permission_classes = api_settings.DEFAULT_PERMISSION_CLASSES
    ...

I'm not sure if using a @property permission_classes is a good or bad idea, but it doesn't seem to be common.

#4 Updated by ipanova@redhat.com 24 days ago

  • Status changed from NEW to CLOSED - NOTABUG

Please re-open if you still experience the issue.

Please register to edit this issue

Also available in: Atom PDF