MD-Studio / MDStudio

A general framework for microservice based distributed applications
Apache License 2.0
12 stars 0 forks source link

Error import ContextManager #95

Closed felipeZ closed 6 years ago

felipeZ commented 6 years ago

When calling the main.py function for my component I got the following error:

(lie_md-GRAco0qo) root@49210f2d63e1:/app/components/lie_md/lie_md# python .
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "./__main__.py", line 1, in <module>
    from mdstudio.runner import main
  File "/app/mdstudio/mdstudio/runner.py", line 12, in <module>
    from mdstudio.component.impl.common import CommonSession
  File "/app/mdstudio/mdstudio/component/impl/common.py", line 16, in <module>
    from mdstudio.api.context import UserContext, GroupRoleContext, GroupContext, ContextManager
  File "/app/mdstudio/mdstudio/api/context.py", line 6, in <module>
    from mdstudio.cache.cache_type import CacheType
  File "/app/mdstudio/mdstudio/cache/__init__.py", line 2, in <module>
    from mdstudio.service.cache import Cache
  File "/app/mdstudio/mdstudio/service/cache.py", line 6, in <module>
    from mdstudio.cache.impl.connection import GlobalCache
  File "/app/mdstudio/mdstudio/cache/impl/connection.py", line 4, in <module>
    from mdstudio.cache.session_cache import SessionCacheWrapper
  File "/app/mdstudio/mdstudio/cache/session_cache.py", line 5, in <module>
    from mdstudio.api.context import ContextManager
ImportError: cannot import name 'ContextManager'

When I try to load the class ContextManager from ipython I got the following error:

(lie_md-GRAco0qo) root@49210f2d63e1:/app/components/lie_md/lie_md# ipython
Python 3.6.3 (default, Nov  4 2017, 22:17:09) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from mdstudio.api.context import ContextManager
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-75b8b6456e23> in <module>()
----> 1 from mdstudio.api.context import ContextManager

/app/mdstudio/mdstudio/api/context.py in <module>()
      4 
      5 from mdstudio.api.singleton import Singleton
----> 6 from mdstudio.cache.cache_type import CacheType
      7 from mdstudio.db.connection_type import ConnectionType
      8 from mdstudio.logging.log_type import LogType

/app/mdstudio/mdstudio/cache/__init__.py in <module>()
      1 from mdstudio.cache.cache_type import CacheType
----> 2 from mdstudio.service.cache import Cache

/app/mdstudio/mdstudio/service/cache.py in <module>()
      4 from mdstudio.cache.cache import ICache
      5 from mdstudio.cache.cache_type import CacheType
----> 6 from mdstudio.cache.impl.connection import GlobalCache
      7 
      8 

/app/mdstudio/mdstudio/cache/impl/connection.py in <module>()
      2 
      3 from mdstudio.api.singleton import Singleton
----> 4 from mdstudio.cache.session_cache import SessionCacheWrapper
      5 from mdstudio.session import GlobalSession
      6 

/app/mdstudio/mdstudio/cache/session_cache.py in <module>()
      3 from mdstudio.cache import CacheType
      4 from mdstudio.cache.cache import ICache
----> 5 from mdstudio.api.context import ContextManager
      6 
      7 

ImportError: cannot import name 'ContextManager'

Is this a circular import issue? Have you run into the same problem?

felipeZ commented 6 years ago

I have solved the issue by replacing the called to ContextManager in the session_cache module

# from mdstudio.api.context import ContextManager
import mdstudio
...

    def _call(self, uri, request):
        return self.session.call('mdstudio.cache.endpoint.{}'.format(uri), request, claims=mdstudio.api.context.ContextManager.get('call_context').get_cache_claims(self.cache_type))