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 in models.system_settings.py #11137

Open
jacobtylerwalls opened this issue Jul 5, 2024 · 0 comments
Open

Circular import in models.system_settings.py #11137

jacobtylerwalls opened this issue Jul 5, 2024 · 0 comments

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Jul 5, 2024

Importing arches.app.models is a bit fragile because arches.app.models.system_settings also imports from arches.app.models import models, which it only needs in a couple of instance methods.

Discovered in #11016, where we worked around this by just avoiding system_settings.py altogether:

Yep, if you don't hide the circular import like this, you get this when transmitting settings.py to nodejs:

  File "/Users/jwalls/prj/arches/arches/app/utils/thumbnail_factory.py", line 48, in <module>
    ThumbnailGeneratorInstance = ThumbnailFactory().create()
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/prj/arches/arches/app/utils/thumbnail_factory.py", line 29, in create
    if settings.THUMBNAIL_GENERATOR:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/prj/arches/arches/app/models/system_settings.py", line 69, in __getattr__
    self.update_from_db()
  File "/Users/jwalls/prj/arches/arches/app/models/system_settings.py", line 90, in update_from_db
    from arches.app.datatypes.datatypes import DataTypeFactory
  File "/Users/jwalls/prj/arches/arches/app/datatypes/datatypes.py", line 29, in <module>
    from arches.app.utils.permission_backend import user_is_resource_reviewer
  File "/Users/jwalls/prj/arches/arches/app/utils/permission_backend.py", line 19, in <module>
    from arches.app.models.models import ResourceInstance, MapLayer
ImportError: cannot import name 'ResourceInstance' from partially initialized module 'arches.app.models.models' (most likely due to a circular import) (/Users/jwalls/prj/arches/arches/app/models/models.py)

Originally posted by @jacobtylerwalls in #11016 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant