Skip to content

Upgrade to SQLAlchemy 1.4 and dynamicannotationdb 5.15.1 - #281

Merged
fcollman merged 3 commits into
masterfrom
sqlalchemy-1.4-upgrade
Nov 26, 2026
Merged

fcollman merged 3 commits into
masterfrom
sqlalchemy-1.4-upgrade

Conversation

@fcollman

@fcollman fcollman commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Moves MaterializationEngine from SQLAlchemy 1.3.24 to 1.4.54 so it can take dynamicannotationdb 5.15.1, which requires SQLAlchemy >= 1.4.

Deploy dependency

Merge and deploy CAVEconnectome/cave-helm-charts#20 first. The chart sets SQLALCHEMY_DATABASE_URI to postgres://..., and SQLAlchemy 1.4 rejects that scheme (NoSuchModuleError). This PR does not normalise the scheme in code, so with the current chart every database connection would fail. The test suite cannot see this because the test config uses postgresql://.

Dependency changes

Package From To
sqlalchemy 1.3.24 1.4.54
dynamicannotationdb 5.14.1 5.15.1
geoalchemy2 0.11.1 0.21.0
emannotationschemas 5.25.1 5.26.3

The last two are pulled in by the first two, not chosen here.

Code changes

Found by the existing tests:

  • Removed module. sqlalchemy.ext.declarative.api no longer exists; query_manager.py imports DeclarativeMeta from sqlalchemy.orm.
  • Dialect.has_table() needs a Connection. Four call sites passed an Engine; they now use inspect(engine).has_table().
  • Index reflection. 1.4 reports dialect_options for every index on PostgreSQL 11+ ({"postgresql_include": []}), so index_manager.get_table_indices left plain indexes without a type. It now classifies by access method.
  • Row as a bind parameter. update_table_metadata passed a .first() result as analysisversion_id. A 1.4 Row is not a tuple, so psycopg2 cannot adapt it; it now uses .scalar().

Not caught by the existing tests:

  • desired_resolution returned wrong positions with HTTP 200. QueryManager multiplies an integer cast by a numpy float. 1.4 rendered that literal through int(), so a 0.5 ratio became 0 and 2.5 became 2. Fixed with float().
  • find_ids_with_specified_roots produced invalid SQL. It stringified an IN query without literal_binds, which on 1.4 leaves IN (__[POSTCOMPILE_...]) in the text.
  • DevConfig used postgres://.

Tests

  • TestQueryDesiredResolution queries the frozen endpoint at 0.5x, 2.5x and 4x the table resolution on both fetch paths and checks every position column.
  • TestFindIdsWithSpecifiedRoots executes the returned statements and checks they select the rows with those root ids.

Both fail on 1.4 without their fix. Both also pass against unmodified master on 1.3, so they describe existing behaviour.

Full suite locally (macOS, PostGIS 18): 905 passed, 2 skipped on 1.4. master on 1.3 was 898 passed, 2 skipped before these tests were added.

CI

CI now runs against postgis/postgis:18-3.6 instead of 13-master (second commit). ubuntu-latest is now Ubuntu 26.04, whose pg_dump emits SET transaction_timeout; the PostgreSQL 13 service rejected it, so test_clustered_staging_table_transfers_in_id_order copied 0 rows and failed. This is independent of the SQLAlchemy change and would fail on master too. tests/test_data/mat_metadata.json (the image the tests' --docker mode starts) is changed to match.

CI also gets a redis:7 service on port 6390 (third commit). Five test modules need a real redis there and skip without it, so CI had been skipping 55 tests; it now runs all of them: 907 passed, 0 skipped.

How this was checked beyond the suite

  • QueryManager was driven offline in both versions across 30 scenarios (live and frozen modes, reference joins, suffixes, spatial filters, sampling). The generated SQL is identical apart from the desired_resolution case fixed here, an equivalent rewrite of empty IN, and filter_out_dict with a list, which is invalid SQL on 1.3 as well.
  • The frozen query endpoint was called with 13 requests on both fetch paths in both versions. Responses are identical apart from desired_resolution.

Not addressed

  • Statement cache memory. 1.4 keeps up to about 750 compiled statements per engine. The root-id workflows execute large literal IN lists as text(), so worker memory may grow. Not measured on real workloads.
  • user_id column type. From the emannotationschemas diff, a few schemas' user_id fields now map to BigInteger instead of Integer. The effect on existing tables and result dtypes was not tested.
  • 2.0 deprecations. The suite raises RemovedIn20Warning for raw-string execute, Row.keys(), from_self and legacy select([...]). None break on 1.4.
  • Live-mode queries were compared as generated SQL only, not executed. Views were not covered.

🤖 Generated with Claude Code

fcollman and others added 3 commits November 25, 2026 23:26
dynamicannotationdb 5.15.x requires SQLAlchemy >= 1.4, so the pin moves
from <1.4 to >=1.4,<2. The lock also moves geoalchemy2 0.11.1 -> 0.21.0
and emannotationschemas 5.25.1 -> 5.26.3.

Changes needed for 1.4:
- query_manager: import DeclarativeMeta from sqlalchemy.orm; the
  sqlalchemy.ext.declarative.api module was removed.
- Dialect.has_table() needs a Connection, not an Engine: use
  inspect(engine).has_table() at the four call sites.
- index_manager: 1.4 reports dialect_options for every index on
  PostgreSQL 11+, so classify an index by its access method.
- update_table_metadata: read the version id with .scalar(); a Row is
  no longer a tuple and psycopg2 cannot adapt it as a parameter.
- QueryManager: convert the desired_resolution ratio with float().
  1.4 rendered the numpy float through the integer cast's int(), so
  0.5 became 0 and positions came back wrong with a 200.
- find_ids_with_specified_roots: compile with literal_binds. 1.4
  leaves an IN list as a placeholder in the stringified statement.
- DevConfig: postgresql://, since 1.4 rejects the postgres:// scheme.

Tests cover the desired_resolution scaling and the root-id statements.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The ubuntu-latest runner is now Ubuntu 26.04, whose pg_dump emits
"SET transaction_timeout", which the PostgreSQL 13 service rejects. That
failed test_clustered_staging_table_transfers_in_id_order: the transfer
copied 0 rows.

Move the CI service, and the image the tests' --docker mode starts, from
postgis/postgis:13-master to postgis/postgis:18-3.6.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Five test modules need a real redis on localhost:6390 and skip without
it, so CI was skipping 53 tests. Add a redis:7 service on that port.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@fcollman
fcollman merged commit 706c2f1 into master Nov 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant