From b3f887208a7bd20fa1f2b5e6f9a1598855794ea5 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 22 Nov 2023 08:42:19 +0100 Subject: [PATCH 1/4] Fix numeric check for tilitid values --- modelbaker/dbconnector/gpkg_connector.py | 3 ++- modelbaker/dbconnector/mssql_connector.py | 18 +++++++++++++++++- modelbaker/dbconnector/pg_connector.py | 20 +++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/modelbaker/dbconnector/gpkg_connector.py b/modelbaker/dbconnector/gpkg_connector.py index 1b90c33..e7b878a 100644 --- a/modelbaker/dbconnector/gpkg_connector.py +++ b/modelbaker/dbconnector/gpkg_connector.py @@ -16,6 +16,7 @@ ***************************************************************************/ """ import errno +import numbers import os import re import sqlite3 @@ -883,7 +884,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): if not tilitid_value: # default value tilitid_value = f"'{uuid.uuid4()}'" - elif not tilitid_value.isnumeric(): + elif not isinstance(tilitid_value, numbers.Number): tilitid_value = f"'{tilitid_value}'" cursor.execute( """ diff --git a/modelbaker/dbconnector/mssql_connector.py b/modelbaker/dbconnector/mssql_connector.py index d1c595c..0953edf 100644 --- a/modelbaker/dbconnector/mssql_connector.py +++ b/modelbaker/dbconnector/mssql_connector.py @@ -16,6 +16,7 @@ ***************************************************************************/ """ +import numbers import re import pyodbc @@ -984,8 +985,23 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): if not tilitid_value: # default value tilitid_value = "NEWID()" - elif not tilitid_value.isnumeric(): + elif not isinstance(tilitid_value, numbers.Number): tilitid_value = f"'{tilitid_value}'" + print( + """ + INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) + VALUES (NEXT VALUE FOR {schema}.{sequence}, {dataset_tid}, '{topic}', {tilitid}, 'modelbaker') + """.format( + schema=self.schema, + sequence="t_ili2db_seq", + tid_name=self.tid, + tilitid_name=self.tilitid, + basket_table=BASKET_TABLE, + dataset_tid=dataset_tid, + topic=topic, + tilitid=tilitid_value, + ) + ) cur.execute( """ INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 2319b87..373489d 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -17,6 +17,7 @@ ***************************************************************************/ """ import logging +import numbers import re import psycopg2 @@ -1020,11 +1021,28 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): topic ) try: + print(tilitid_value) if not tilitid_value: # default value tilitid_value = "uuid_generate_v4()" - elif not tilitid_value.isnumeric(): + elif not isinstance(tilitid_value, numbers.Number): tilitid_value = f"'{tilitid_value}'" + print(tilitid_value) + print( + """ + INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) + VALUES (nextval('{schema}.{sequence}'), {dataset_tid}, '{topic}', {tilitid}, 'modelbaker') + """.format( + schema=self.schema, + sequence="t_ili2db_seq", + tid_name=self.tid, + tilitid_name=self.tilitid, + basket_table=PG_BASKET_TABLE, + dataset_tid=dataset_tid, + topic=topic, + tilitid=tilitid_value, + ) + ) cur.execute( """ INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) From 35c84ee63cd8e0afbc0b353e8fa46cfaa1a69f34 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 24 Nov 2023 11:17:32 +0100 Subject: [PATCH 2/4] Update modelbaker/dbconnector/mssql_connector.py --- modelbaker/dbconnector/mssql_connector.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/modelbaker/dbconnector/mssql_connector.py b/modelbaker/dbconnector/mssql_connector.py index 0953edf..73868d5 100644 --- a/modelbaker/dbconnector/mssql_connector.py +++ b/modelbaker/dbconnector/mssql_connector.py @@ -987,21 +987,6 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): tilitid_value = "NEWID()" elif not isinstance(tilitid_value, numbers.Number): tilitid_value = f"'{tilitid_value}'" - print( - """ - INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) - VALUES (NEXT VALUE FOR {schema}.{sequence}, {dataset_tid}, '{topic}', {tilitid}, 'modelbaker') - """.format( - schema=self.schema, - sequence="t_ili2db_seq", - tid_name=self.tid, - tilitid_name=self.tilitid, - basket_table=BASKET_TABLE, - dataset_tid=dataset_tid, - topic=topic, - tilitid=tilitid_value, - ) - ) cur.execute( """ INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) From c2ae1c9623fd97c5500030f8fb0622bb72540de6 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 24 Nov 2023 11:18:16 +0100 Subject: [PATCH 3/4] Update modelbaker/dbconnector/pg_connector.py --- modelbaker/dbconnector/pg_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 373489d..20b581e 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -1021,7 +1021,6 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): topic ) try: - print(tilitid_value) if not tilitid_value: # default value tilitid_value = "uuid_generate_v4()" From 90462e8c19f1407f444cf679741930092ee229ad Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 24 Nov 2023 11:18:50 +0100 Subject: [PATCH 4/4] Update modelbaker/dbconnector/pg_connector.py --- modelbaker/dbconnector/pg_connector.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 20b581e..70b8d8c 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -1026,22 +1026,6 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None): tilitid_value = "uuid_generate_v4()" elif not isinstance(tilitid_value, numbers.Number): tilitid_value = f"'{tilitid_value}'" - print(tilitid_value) - print( - """ - INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey ) - VALUES (nextval('{schema}.{sequence}'), {dataset_tid}, '{topic}', {tilitid}, 'modelbaker') - """.format( - schema=self.schema, - sequence="t_ili2db_seq", - tid_name=self.tid, - tilitid_name=self.tilitid, - basket_table=PG_BASKET_TABLE, - dataset_tid=dataset_tid, - topic=topic, - tilitid=tilitid_value, - ) - ) cur.execute( """ INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey )