Issue #8537
closednamed_viewsets erroneously contains models/viewsets from other apps
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.
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
Updated by daviddavis about 3 years ago
- Status changed from NEW to CLOSED - WONTFIX
Closing since this problem hasn't impacted users/plugin writers.