Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numeric check for tilitid values #75

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/
"""
import errno
import numbers
import os
import re
import sqlite3
Expand Down Expand Up @@ -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(
"""
Expand Down
3 changes: 2 additions & 1 deletion modelbaker/dbconnector/mssql_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/
"""

import numbers
import re

import pyodbc
Expand Down Expand Up @@ -984,7 +985,7 @@ 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}'"
cur.execute(
"""
Expand Down
19 changes: 18 additions & 1 deletion modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
***************************************************************************/
"""
import logging
import numbers
import re

import psycopg2
Expand Down Expand Up @@ -1023,8 +1024,24 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
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,
)
)
signedav marked this conversation as resolved.
Show resolved Hide resolved
cur.execute(
"""
INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey )
Expand Down
Loading