Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular import when bumping galaxy to 2.19.0 #1561

Closed
rochacbruno opened this issue Mar 18, 2024 · 2 comments · Fixed by #1564
Closed

Circular import when bumping galaxy to 2.19.0 #1561

rochacbruno opened this issue Mar 18, 2024 · 2 comments · Fixed by #1564
Assignees
Labels

Comments

@rochacbruno
Copy link
Member

pulp-1          | s6-rc: info: service oci-env-prepare successfully started
pulp-1          | s6-rc: info: service postgres-prepare: starting
pulp-1          | Calling /etc/init/postgres-prepare
pulp-1          | ALTER DATABASE
pulp-1          | [oneshot] postgres-prepare: running Pulp migrations
pulp-1          | Traceback (most recent call last):
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/settings.py", line 177, in import_from_string
pulp-1          |     return import_string(val)
pulp-1          |            ^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/utils/module_loading.py", line 30, in import_string
pulp-1          |     return cached_import(module_path, class_name)
pulp-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/utils/module_loading.py", line 15, in cached_import
pulp-1          |     module = import_module(module_path)
pulp-1          |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
pulp-1          |     return _bootstrap._gcd_import(name[level:], package, level)
pulp-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
pulp-1          |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
pulp-1          |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
pulp-1          |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
pulp-1          |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
pulp-1          |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
pulp-1          |   File "/src/galaxy_ng/galaxy_ng/app/access_control/access_policy.py", line 23, in <module>
pulp-1          |     from galaxy_ng.app.api.v1.models import LegacyNamespace
pulp-1          |   File "/src/galaxy_ng/galaxy_ng/app/api/v1/models.py", line 5, in <module>
pulp-1          |     from galaxy_ng.app.models import Namespace
pulp-1          | ImportError: cannot import name 'Namespace' from partially initialized module 'galaxy_ng.app.models' (most likely due to a circular import) (/src/galaxy_ng/galaxy_ng/app/models/__init__.py)
pulp-1          | 
pulp-1          | During handling of the above exception, another exception occurred:
pulp-1          | 
pulp-1          | Traceback (most recent call last):
pulp-1          |   File "/usr/local/bin/pulpcore-manager", line 8, in <module>
pulp-1          |     sys.exit(manage())
pulp-1          |              ^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/pulpcore/app/manage.py", line 11, in manage
pulp-1          |     execute_from_command_line(sys.argv)
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
pulp-1          |     utility.execute()
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 416, in execute
pulp-1          |     django.setup()
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
pulp-1          |     apps.populate(settings.INSTALLED_APPS)
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
pulp-1          |     app_config.import_models()
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
pulp-1          |     self.models_module = import_module(models_module_name)
pulp-1          |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
pulp-1          |     return _bootstrap._gcd_import(name[level:], package, level)
pulp-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
pulp-1          |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
pulp-1          |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
pulp-1          |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
pulp-1          |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
pulp-1          |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
pulp-1          |   File "/src/galaxy_ng/galaxy_ng/app/models/__init__.py", line 5, in <module>
pulp-1          |     from .container import (
pulp-1          |   File "/src/galaxy_ng/galaxy_ng/app/models/container.py", line 3, in <module>
pulp-1          |     from pulp_container.app import models as container_models
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/pulp_container/app/models.py", line 34, in <module>
pulp-1          |     from pulp_container.app.utils import get_content_data
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/pulp_container/app/utils.py", line 19, in <module>
pulp-1          |     from pulp_container.app.exceptions import ManifestInvalid
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/pulp_container/app/exceptions.py", line 1, in <module>
pulp-1          |     from rest_framework import status, views
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 17, in <module>
pulp-1          |     from rest_framework.schemas import DefaultSchema
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/schemas/__init__.py", line 34, in <module>
pulp-1          |     permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
pulp-1          |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/settings.py", line 225, in __getattr__
pulp-1          |     val = perform_import(val, attr)
pulp-1          |           ^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/settings.py", line 168, in perform_import
pulp-1          |     return [import_from_string(item, setting_name) for item in val]
pulp-1          |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/settings.py", line 168, in <listcomp>
pulp-1          |     return [import_from_string(item, setting_name) for item in val]
pulp-1          |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/rest_framework/settings.py", line 180, in import_from_string
pulp-1          |     raise ImportError(msg)
pulp-1          | ImportError: Could not import 'galaxy_ng.app.access_control.access_policy.AccessPolicyBase' for API setting 'DEFAULT_PERMISSION_CLASSES'. ImportError: cannot import name 'Namespace' from partially initialized module 'galaxy_ng.app.models' (most likely due to a circular import) (/src/galaxy_ng/galaxy_ng/app/models/__init__.py).
@lubosmj
Copy link
Member

lubosmj commented Mar 18, 2024

We may want to move validate_manifest from utils.py to json_schemas.py:

def validate_manifest(content_data, media_type, digest):

@lubosmj
Copy link
Member

lubosmj commented Mar 18, 2024

In the latest release (2.19), we extracted the get_content_data function from the sync pipeline and put it into utils.py. As a result of this, galaxy_ng experiences this error:

pulp-1          |   File "/src/galaxy_ng/galaxy_ng/app/models/container.py", line 3, in <module>
pulp-1          |     from pulp_container.app import models as container_models
pulp-1          |   File "/usr/local/lib/python3.11/site-packages/pulp_container/app/models.py", line 34, in <module>
pulp-1          |     from pulp_container.app.utils import get_content_data

It appears that the placement uncovered the real issue of misplacing validate_manifest to utils.py.

@lubosmj lubosmj self-assigned this Mar 19, 2024
lubosmj added a commit to lubosmj/pulp_container that referenced this issue Mar 19, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes pulp#1561
lubosmj added a commit to lubosmj/pulp_container that referenced this issue Mar 19, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes pulp#1561
lubosmj added a commit to lubosmj/pulp_container that referenced this issue Mar 19, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes pulp#1561
patchback bot pushed a commit that referenced this issue Mar 20, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes #1561

(cherry picked from commit 64f427d)
lubosmj added a commit that referenced this issue Mar 20, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes #1561
patchback bot pushed a commit that referenced this issue Mar 20, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes #1561

(cherry picked from commit 64f427d)
lubosmj added a commit that referenced this issue Mar 20, 2024
The exception handler should be closer to APIView classes where it is
actually being used. At the same time, this resolves the circular import
errors caused by the recent extraction of the get_content_data method.

closes #1561

(cherry picked from commit 64f427d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Status: Shipped
Development

Successfully merging a pull request may close this issue.

2 participants