mara_db.dbs.PostgreSQLDB does not work with port given as int
akreuzer opened this issue · 0 comments
akreuzer commented
Running the following piece of code results in the exception below.
import mara_db.auto_migration
import mara_db.config
import mara_db.dbs
mara_db.config.databases = lambda: {
"mara": mara_db.dbs.PostgreSQLDB(
host="localhost", port=32768, user="postgres", database="example_etl_mara"
)
}
print(mara_db.auto_migration.engine("mara"))
Exception:
<ipython-input-1-016eb66e9ef8> in <module>()
9 }
10
---> 11 print(mara_db.auto_migration.engine("mara"))
~/.python_envs/test/lib/python3.7/functools.py in wrapper(*args, **kw)
818
819 def wrapper(*args, **kw):
--> 820 return dispatch(args[0].__class__)(*args, **kw)
821
822 registry[object] = func
~/.python_envs/test/lib/python3.7/site-packages/mara_db/auto_migration.py in __(alias, **_)
141 @engine.register(str)
142 def __(alias: str, **_):
--> 143 return engine(mara_db.dbs.db(alias))
144
145
~/.python_envs/test/lib/python3.7/functools.py in wrapper(*args, **kw)
818
819 def wrapper(*args, **kw):
--> 820 return dispatch(args[0].__class__)(*args, **kw)
821
822 registry[object] = func
~/.python_envs/test/lib/python3.7/site-packages/mara_db/auto_migration.py in __(db)
152 def __(db: mara_db.dbs.PostgreSQLDB):
153 return sqlalchemy.create_engine(
--> 154 f'postgresql+psycopg2://{db.user}{":"+db.password if db.password else ""}@{db.host}{":"+db.port if db.port else "" }/{db.database}')
155
156
TypeError: can only concatenate str (not "int") to str
Passing the port as a string works.
I would have excepted that port is casted to str
or that a more informative error is throw at the creation of the PostgreSQLDB
object.