Project

Profile

Help

Issue #8537

closed

named_viewsets erroneously contains models/viewsets from other apps

Added by daviddavis about 3 years ago. Updated about 3 years ago.

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

Description

For each app, we have this named_viewsets attribute that maps models to NamedModelViewSets.

If you examine it for a plugin:

from pulpcore.app.apps import pulp_plugin_configs
pulp_file_config = [c for c in pulp_plugin_configs() if c.label == "file"][0]
print(pulp_file_config.named_viewsets)

You'll see that it contains mappings for models/viewsets outside of the plugin. For example, pulp_file maps models like Repository to RepositoryViewSet:

pulpcore.app.models.repository.Repository: [pulpcore.app.viewsets.repository.RepositoryViewSet],

This is because pulp_file imports these models/viewsets into its viewsets module.

And the code that sets named_viewsets for apps just blindly imports everything from the viewset module.

This could lead to problems when we call get_viewset_for_model as we iterated through all plugin configs to find mappings. So one plugin could accidentally define a mapping for core for example.

Actions #1

Updated by daviddavis about 3 years ago

Here is an easy reproducer that demonstrates the problem. Uninstall and plugins aside from core and run this in a shell:

In [1]: from pulpcore.app.util import get_viewset_for_model

In [2]: get_viewset_for_model(Repository())

LookupError: Could not determine ViewSet base name for model <class 'pulpcore.app.models.repository.Repository'>

Now if you install a plugin (e.g. pulp_file) it magically works:

In [1]: from pulpcore.app.util import get_viewset_for_model

In [2]: get_viewset_for_model(Repository())
Out[2]: pulpcore.app.viewsets.repository.RepositoryViewSet
Actions #2

Updated by daviddavis about 3 years ago

  • Status changed from NEW to CLOSED - WONTFIX

Closing since this problem hasn't impacted users/plugin writers.

Also available in: Atom PDF