Skip to content

Commit

Permalink
Update sql_implementation.py to include sqlachemy output in debug log…
Browse files Browse the repository at this point in the history
…ging. (#782)

* Update sql_implementation.py to include sqlachemy output in debug logging.

The current logging scheme directly prints the query as rendered by str(q); the following is the output from logging.info(f"ECA query: {q}") in function _equivalent_class_relationships.

INFO:root:ECA query: SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object
FROM statements
WHERE statements.predicate = ? AND statements.object IN (__[POSTCOMPILE_object_1]) AND statements.object IN (SELECT class_node.id
FROM class_node)

With this change, when running at logging level DEBUG, anytime a query is executed sqlachemy will also writes it's logging output, which is the following:
INFO:sqlalchemy.engine.Engine:SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object
FROM statements
WHERE statements.predicate = ? AND statements.object IN (?) AND statements.object IN (SELECT class_node.id
FROM class_node)
INFO:sqlalchemy.engine.Engine:[generated in 0.00023s] ('owl:equivalentClass', 'MONDO:0000550')

In the Sqlalchemy logging, the ambiguous term "(__[POSTCOMPILE_object_1])" isn't stated and instead replaced with a query parameter, and the query parameters are outputted on a second line.

* Update sql_implementation.py

Corrected lint errors
  • Loading branch information
DnlRKorn authored Jul 31, 2024
1 parent 8d3d2db commit a112885
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/oaklib/implementations/sqldb/sql_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ def __post_init__(self):
logging.info(f"Locator, post-processed: {locator}")
self.engine = create_engine(locator)

if(logging.root.level <= logging.DEBUG):
#If oaklib is running at DEBUG level logging; record all queries from sqlachemy on execution.
#This line is equivalent to create_engine(locator,echo=True)
logging.getLogger('sqlalchemy.engine.Engine').setLevel(logging.INFO)

@property
def session(self):
if self._session is None:
Expand Down

0 comments on commit a112885

Please sign in to comment.