Proteus: _thread._local' object has no attribute 'current'

Hello I am trying to connect with Proteus to make consult to the database and I am having this problem, when I make the consultation.

File "/home/hidura/Documents/RESTPOS/clientPOS/app.py", line 23, in hello
    User_tbl = Model.get('res.user')
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/proteus/__init__.py", line 758, in get
    class Spam(Model, metaclass=MetaModelFactory(name, config=config)()):
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/proteus/__init__.py", line 466, in __init__
    self.config = config or proteus.config.get_config()
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/proteus/config.py", line 359, in get_config
    return _CONFIG.current
AttributeError: '_thread._local' object has no attribute 'current'
127.0.0.1 - - [31/Mar/2020 21:43:41] "GET / HTTP/1.1" 500 -

This is the config:

config = config.set_trytond(‘sugelico’)

If I add the config file, still have the same problem.

Thanks in advance.

If you are using proteus in a multihread environment, you must set the configuration for each thread and use Model class from the same thread configuration.

Ok, so I put the configuration on the same thread that Im going to create the model.

Hello I’d been trying to work with proteus but still have a issue, I’ve open a python thread not working via the IDE and the mistake is the lack of the module trytond.backend, but i’ve installed

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/proteus/config.py", line 293, in set_trytond
    _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/proteus/config.py", line 244, in __init__
    Pool.start()
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/pool.py", line 104, in start
    register_classes()
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/modules/__init__.py", line 321, in register_classes
    import trytond.ir
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/ir/__init__.py", line 4, in <module>
    from .configuration import *
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/ir/configuration.py", line 3, in <module>
    from ..model import ModelSQL, ModelSingleton, fields
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/model/__init__.py", line 3, in <module>
    from .model import Model
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/model/model.py", line 9, in <module>
    from trytond.model import fields
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/model/fields/__init__.py", line 4, in <module>
    from .field import *
  File "/snap/pycharm-professional/192/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/model/fields/field.py", line 21, in <module>
    Database = backend.get('Database')
  File "/home/hidura/Documents/RESTPOS/server/TrytonREST/env/lib/python3.7/site-packages/trytond/backend/__init__.py", line 25, in get
    module = importlib.import_module(modname)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'trytond.backend.'

This happen when I try to make the config.set_trytond(‘dbname’, user=‘username’)

It seems that you are passing an empty database uri to the tryton server as it uses an empty string for the backend. You should set a valid database uri to fix this error.