Exception while adding read/write hosts to configuration.
MAnfal opened this issue · comments
Anfal Mushtaq commented
I am trying to specify read/write hosts in the configuration but it is causing exceptions. I am providing my configuration dictionary and the resulting exception below. Please note that if I replace the read/write dictionaries with just a simple host value, it starts working.
Configuration
{
"mysql":{
"driver":"mysql",
"port":4306,
"database":"db",
"user":"default",
"password":"toor",
"prefix":"",
"log_queries":true,
"read":{
"host":"127.0.0.1"
},
"write":{
"host":"127.0.0.1"
}
}
}
Exception
Traceback (most recent call last):
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 64, in __getattr__
return type.__getattribute__(cls, item)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'BaseModel' has no attribute 'boot_base_model'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 64, in __getattr__
return type.__getattribute__(cls, item)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Model' has no attribute 'boot_model'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Projects/project/test.py", line 3, in <module>
user = User.find(1)
^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 572, in find
instance = cls()
^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 129, in __init__
self._boot_if_not_booted()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 156, in _boot_if_not_booted
klass._boot()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 174, in _boot
cls._boot_mixins()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 194, in _boot_mixins
if hasattr(mixin, method):
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 66, in __getattr__
query = cls.query()
^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 1922, in query
return cls().new_query()
^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 129, in __init__
self._boot_if_not_booted()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 156, in _boot_if_not_booted
klass._boot()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 174, in _boot
cls._boot_mixins()
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 194, in _boot_mixins
if hasattr(mixin, method):
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 66, in __getattr__
query = cls.query()
^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 1922, in query
return cls().new_query()
^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 1891, in new_query
builder = self.new_query_without_scopes()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 1916, in new_query_without_scopes
builder = self.new_orm_builder(self._new_base_query_builder())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 1943, in _new_base_query_builder
conn = self.get_connection()
^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 2886, in get_connection
return self.resolve_connection(self.__connection__)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/orm/model.py", line 2920, in resolve_connection
return cls.__resolver.connection(connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/database_manager.py", line 42, in connection
connection = self._make_connection(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/database_manager.py", line 133, in _make_connection
return self._factory.make(config, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/connectors/connection_factory.py", line 30, in make
return self._create_read_write_connection(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/connectors/connection_factory.py", line 42, in _create_read_write_connection
connection = self._create_single_connection(self._get_write_config(config))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/connectors/connection_factory.py", line 59, in _get_write_config
write_config = self._get_read_write_config(config, "write")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Projects/project/venv/lib/python3.11/site-packages/orator/connectors/connection_factory.py", line 65, in _get_read_write_config
return random.choice(config[type])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/random.py", line 374, in choice
return seq[self._randbelow(len(seq))]
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 0
Anfal Mushtaq commented
Going to leave this here in case someone else faces this issue. You need to pass a list
of dicts
to both read
and write
keys. Instead of one single dict as mentioned in the docs.
'read': [{'host': self.host_r}],
'write': [{'host': self.host_w}],