From 7e9f78586326ebdf0ed9247613df271e76f91f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanc?= Date: Thu, 18 Apr 2024 18:13:45 +0200 Subject: [PATCH 1/2] chore: upgrade dependencies --- requirements/requirements.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index c61dee2..01c8240 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,7 +1,7 @@ -Flask==2.3.2 -flask-restx==1.1.0 -Flask-JWT-Extended==4.4.4 -SQLAlchemy==1.4.48 -psycopg2==2.9.6 +Flask==3.0.0 +flask-restx==1.3.0 +Flask-JWT-Extended==4.6.0 +SQLAlchemy==2.0.29 +psycopg2==2.9.9 requests==2.31.0 -qwc-services-core==1.3.19 +qwc-services-core==1.3.26 From accfc55f99ce6134dc0b8832cd5c2fe8288f26d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanc?= Date: Thu, 18 Apr 2024 18:14:53 +0200 Subject: [PATCH 2/2] fix: use context manager to connect to database --- search_service.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/search_service.py b/search_service.py index 0bab5b0..4c13526 100644 --- a/search_service.py +++ b/search_service.py @@ -60,16 +60,18 @@ def search(self, searchtext): ) ) self.logger.debug(f"SQL Query : {sql}") - conn = self.db_engine.db_engine(document["db_url"]).connect() results[key] = [] - try: - result = conn.execute(sql) - for row in result: - row_result = self._feature_from_query(row, document["primary_key"]) - results[key].append(row_result) - self.logger.debug(f"SQL Result for document {key} : {results[key]}") - except Exception as e: - self.logger.error(f"Error for document {key} on query {sql}: {e}") + with self.db_engine.db_engine(document["db_url"]).connect() as conn: + try: + result = conn.execute(sql) + for row in result: + row_result = self._feature_from_query( + row, document["primary_key"] + ) + results[key].append(row_result) + self.logger.debug(f"SQL Result for document {key} : {results[key]}") + except Exception as e: + self.logger.error(f"Error for document {key} on query {sql}: {e}") return results def _feature_from_query(self, row, primary_key):