From 1349cb35b68d278f1067ff5a1d00d47527ddea1c Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Sun, 8 Sep 2024 09:02:13 +0300 Subject: [PATCH] feat: SQLAlchemy v2 support --- ckanext/dcat/harvesters/_json.py | 4 +++- ckanext/dcat/harvesters/rdf.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ckanext/dcat/harvesters/_json.py b/ckanext/dcat/harvesters/_json.py index 5eea7ac0..c058bc54 100644 --- a/ckanext/dcat/harvesters/_json.py +++ b/ckanext/dcat/harvesters/_json.py @@ -6,6 +6,7 @@ import uuid import requests +import sqlalchemy as sa from ckan import model from ckan import logic @@ -273,7 +274,8 @@ def import_stage(self, harvest_object): # the harvest object id (on the after_show hook from the harvester # plugin) model.Session.execute( - 'SET CONSTRAINTS harvest_object_package_id_fkey DEFERRED') + sa.text('SET CONSTRAINTS harvest_object_package_id_fkey DEFERRED') + ) model.Session.flush() elif status == 'change': diff --git a/ckanext/dcat/harvesters/rdf.py b/ckanext/dcat/harvesters/rdf.py index 564ba1af..7bc402e3 100644 --- a/ckanext/dcat/harvesters/rdf.py +++ b/ckanext/dcat/harvesters/rdf.py @@ -6,6 +6,8 @@ import hashlib import traceback +import sqlalchemy as sa + import ckan.plugins as p import ckan.model as model @@ -278,7 +280,7 @@ def import_stage(self, harvest_object): harvest_object.guid)) except p.toolkit.ObjectNotFound: log.info('Package {0} already deleted.'.format(harvest_object.package_id)) - + return True if harvest_object.content is None: @@ -392,7 +394,9 @@ def import_stage(self, harvest_object): # Defer constraints and flush so the dataset can be indexed with # the harvest object id (on the after_show hook from the harvester # plugin) - model.Session.execute('SET CONSTRAINTS harvest_object_package_id_fkey DEFERRED') + model.Session.execute( + sa.text('SET CONSTRAINTS harvest_object_package_id_fkey DEFERRED') + ) model.Session.flush() p.toolkit.get_action('package_create')(context, dataset)