Created
January 23, 2022 01:42
-
-
Save mohitt/da9cc416fe43baf0d7f8305b8c4b3447 to your computer and use it in GitHub Desktop.
Exception in sql alchemy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Session created using session maker, asyncpg connection string | |
engine = self.active_session.get_bind() | |
table_name = model_class.__tablename__ | |
schema_name = model_class.__table_args__["schema"] | |
return await engine.dialect.has_table( | |
self.active_session, table_name, schema_name | |
) | |
`has_table` throws following error. | |
def has_table(self, connection, table_name, schema=None): | |
# seems like case gets folded in pg_class... | |
if schema is None: | |
cursor = connection.execute( | |
sql.text( | |
"select relname from pg_class c join pg_namespace n on " | |
"n.oid=c.relnamespace where " | |
"pg_catalog.pg_table_is_visible(c.oid) " | |
"and relname=:name" | |
).bindparams( | |
sql.bindparam( | |
"name", | |
util.text_type(table_name), | |
type_=sqltypes.Unicode, | |
) | |
) | |
) | |
else: | |
cursor = connection.execute( | |
sql.text( | |
"select relname from pg_class c join pg_namespace n on " | |
"n.oid=c.relnamespace where n.nspname=:schema and " | |
"relname=:name" | |
).bindparams( | |
sql.bindparam( | |
"name", | |
util.text_type(table_name), | |
type_=sqltypes.Unicode, | |
), | |
sql.bindparam( | |
"schema", | |
util.text_type(schema), | |
type_=sqltypes.Unicode, | |
), | |
) | |
) | |
> return bool(cursor.first()) | |
E AttributeError: 'coroutine' object has no attribute 'first' | |
../../../.virtualenvs/vocore-IesooB9o/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/base.py:3336: AttributeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment