Skip to content

Commit

Permalink
Fix the types
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Feb 1, 2023
1 parent 132b88a commit e495732
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion c2cwsgiutils/sql_profiler/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions c2cwsgiutils/sqlalchemylogger/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e495732

Please sign in to comment.