datamarket 0.9.24__tar.gz → 0.9.25__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datamarket might be problematic. Click here for more details.
- {datamarket-0.9.24 → datamarket-0.9.25}/PKG-INFO +1 -1
- {datamarket-0.9.24 → datamarket-0.9.25}/pyproject.toml +1 -1
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/alchemy.py +33 -6
- {datamarket-0.9.24 → datamarket-0.9.25}/LICENSE +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/README.md +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/__init__.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/__init__.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/aws.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/drive.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/ftp.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/nominatim.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/peerdb.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/proxy.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/interfaces/tinybird.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/params/__init__.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/params/nominatim.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/__init__.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/airflow.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/alchemy.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/main.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/selenium.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/soda.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/typer.py +0 -0
- {datamarket-0.9.24 → datamarket-0.9.25}/src/datamarket/utils/types.py +0 -0
|
@@ -11,6 +11,7 @@ from sqlalchemy.dialects.postgresql import insert
|
|
|
11
11
|
from sqlalchemy.exc import IntegrityError
|
|
12
12
|
from sqlalchemy.ext.declarative import DeclarativeMeta
|
|
13
13
|
from sqlalchemy.orm import Session, sessionmaker
|
|
14
|
+
from sqlalchemy.sql.expression import ClauseElement
|
|
14
15
|
from enum import Enum
|
|
15
16
|
|
|
16
17
|
########################################################################################################################
|
|
@@ -220,17 +221,43 @@ class AlchemyInterface:
|
|
|
220
221
|
if not silent:
|
|
221
222
|
logger.info(f"upserting {alchemy_obj}")
|
|
222
223
|
|
|
223
|
-
|
|
224
|
-
|
|
224
|
+
table = alchemy_obj.__table__
|
|
225
|
+
primary_keys = list(col.name for col in table.primary_key.columns.values())
|
|
226
|
+
|
|
227
|
+
# Build the dictionary for the INSERT values
|
|
228
|
+
insert_values = {
|
|
229
|
+
col.name: getattr(alchemy_obj, col.name)
|
|
230
|
+
for col in table.columns
|
|
231
|
+
if getattr(alchemy_obj, col.name) is not None # Include all non-None values for insert
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Build the dictionary for the UPDATE set clause
|
|
235
|
+
# Start with values from the object, excluding primary keys
|
|
236
|
+
update_set_values = {
|
|
225
237
|
col.name: val
|
|
226
|
-
for col in
|
|
238
|
+
for col in table.columns
|
|
227
239
|
if col.name not in primary_keys and (val := getattr(alchemy_obj, col.name)) is not None
|
|
228
240
|
}
|
|
229
241
|
|
|
242
|
+
# Add columns with SQL-based onupdate values explicitly to the set clause
|
|
243
|
+
for column in table.columns:
|
|
244
|
+
actual_sql_expression = None
|
|
245
|
+
if column.onupdate is not None:
|
|
246
|
+
if hasattr(column.onupdate, "arg") and isinstance(column.onupdate.arg, ClauseElement):
|
|
247
|
+
# This handles wrappers like ColumnElementColumnDefault,
|
|
248
|
+
# where the actual SQL expression is in the .arg attribute.
|
|
249
|
+
actual_sql_expression = column.onupdate.arg
|
|
250
|
+
elif isinstance(column.onupdate, ClauseElement):
|
|
251
|
+
# This handles cases where onupdate might be a direct SQL expression.
|
|
252
|
+
actual_sql_expression = column.onupdate
|
|
253
|
+
|
|
254
|
+
if actual_sql_expression is not None:
|
|
255
|
+
update_set_values[column.name] = actual_sql_expression
|
|
256
|
+
|
|
230
257
|
statement = (
|
|
231
|
-
insert(
|
|
232
|
-
.values(
|
|
233
|
-
.on_conflict_do_update(index_elements=index_elements, set_=
|
|
258
|
+
insert(table)
|
|
259
|
+
.values(insert_values)
|
|
260
|
+
.on_conflict_do_update(index_elements=index_elements, set_=update_set_values)
|
|
234
261
|
)
|
|
235
262
|
|
|
236
263
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|