From 306cf432da7967b97c4512dcc670a6895dadaec4 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 12 Dec 2025 13:33:10 +0000 Subject: [PATCH 1/2] Update SQLAlchemy and alembic --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b59629b..e9d532e 100755 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ def has_external_dependency(name): try: from setuptools import setup config['install_requires'] = ['requests', 'six', - 'sqlalchemy==1.3.0', 'alembic==1.14.0'], + 'sqlalchemy==1.4.54', 'alembic==1.17.2'], except ImportError: pass From 8cf0697550eab955872d262c0553d0d2cef6a4c5 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 12 Dec 2025 13:37:48 +0000 Subject: [PATCH 2/2] Fix code for SQLAlchemy These fixes are largely for SQLAlchemy v2 compatibility, for which we get warnings for. --- scraperwiki/sql.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scraperwiki/sql.py b/scraperwiki/sql.py index 6507186..138fdea 100644 --- a/scraperwiki/sql.py +++ b/scraperwiki/sql.py @@ -96,8 +96,8 @@ def new_transaction(cls): @classmethod def reflect_metadata(cls): if cls.metadata is None: - cls.metadata = sqlalchemy.MetaData(bind=cls.engine) - cls.metadata.reflect() + cls.metadata = sqlalchemy.MetaData() + cls.metadata.reflect(bind=cls.engine) @classmethod def check_last_committed(cls): @@ -197,7 +197,7 @@ def save(unique_keys, data, table_name='swdata'): raise TypeError("Data must be a single mapping or an iterable " "of mappings") - insert = _State.table.insert(prefixes=['OR REPLACE']) + insert = sqlalchemy.insert(_State.table).prefix_with('OR REPLACE') for row in data: if not isinstance(row, Mapping): raise TypeError("Elements of data must be mappings, got {}".format( @@ -251,7 +251,7 @@ def save_var(name, value): keep_existing=True ) - vars_table.create(bind=connection, checkfirst=True) + vars_table.create(connection, checkfirst=True) column_type = get_column_type(value) @@ -265,8 +265,9 @@ def save_var(name, value): # value_blob=Blob(value), type=column_type.__visit_name__.lower()) - vars_table.insert(prefixes=['OR REPLACE']).values(**values).execute() - + stmt = vars_table.insert(prefixes=['OR REPLACE']).values(**values) + connection.execute(stmt) + _State.new_transaction() def get_var(name, default=None): """