From e4957320c8f0662c01ff6c6cbbe6c73e77efbdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 1 Feb 2023 15:26:38 +0100 Subject: [PATCH] Fix the types --- c2cwsgiutils/sql_profiler/_impl.py | 7 ++++++- c2cwsgiutils/sqlalchemylogger/handlers.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/c2cwsgiutils/sql_profiler/_impl.py b/c2cwsgiutils/sql_profiler/_impl.py index 24c7f25b8..4338bbd47 100644 --- a/c2cwsgiutils/sql_profiler/_impl.py +++ b/c2cwsgiutils/sql_profiler/_impl.py @@ -45,7 +45,12 @@ def profile( LOG.info("parameters: %s", repr(parameters)) with conn.engine.begin() as c: output = "\n ".join( - [row[0] for row in c.execute("EXPLAIN ANALYZE " + statement, parameters)] + [ + row[0] + for row in c.execute( + sqlalchemy.text(f"EXPLAIN ANALYZE {statement}"), parameters + ) + ] ) LOG.info(output) except Exception: # nosec # pylint: disable=broad-except diff --git a/c2cwsgiutils/sqlalchemylogger/handlers.py b/c2cwsgiutils/sqlalchemylogger/handlers.py index ffd852731..f51c71b77 100644 --- a/c2cwsgiutils/sqlalchemylogger/handlers.py +++ b/c2cwsgiutils/sqlalchemylogger/handlers.py @@ -98,9 +98,11 @@ def create_db(self) -> None: if not isinstance(self.Log.__table_args__, type(None)) and self.Log.__table_args__.get( "schema", None ): - if not self.engine.dialect.has_schema(self.engine, self.Log.__table_args__["schema"]): + if not self.engine.dialect.has_schema( + self.engine.raw_connection, self.Log.__table_args__["schema"] + ): with self.engine.begin() as connection: - connection.execute(sqlalchemy.schema.CreateSchema(self.Log.__table_args__["schema"])) + connection.execute(sqlalchemy.schema.CreateSchema(self.Log.__table_args__["schema"])) # type: ignore Base.metadata.create_all(self.engine) def emit(self, record: Any) -> None: