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

mara_db.dbs.PostgreSQLDB does not work with port given as int #11

Closed
akreuzer opened this issue Jul 10, 2018 · 0 comments · Fixed by #12
Closed

mara_db.dbs.PostgreSQLDB does not work with port given as int #11

akreuzer opened this issue Jul 10, 2018 · 0 comments · Fixed by #12

Comments

@akreuzer
Copy link

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.

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

Successfully merging a pull request may close this issue.

1 participant