Rewrite merge methods on real Core constructs so schema_translate_map applies to loaded data - #39
Open
nicoloesch wants to merge 15 commits into
Open
nicoloesch wants to merge 15 commits into
nicoloesch wants to merge 15 commits into
Conversation
added 5 commits
August 28, 2026 01:21
…t SQLAlchemy core objects, update test suite and unify shared backend tests, update schema registration
4 tasks
added 10 commits
September 3, 2026 05:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Depends on AustralianCancerDataNetwork/oa-configurator#37.
Requires
pyproject.tomlversion update foroa-configuratorBreaking change
OrmLoaderConfig.test_orm_dbis gone, replaced bytest_orm_db_pg/test_orm_db_sqlite. Anyonewith
test_orm_dbset in theiromop.configwill need to update it — there is no back-compatshim. Needed because dialect-specific integration tests require a guaranteed-correct-dialect test
database each, which one shared field couldn't express.
Root cause
Four related ways
schema_translate_mapwas silently bypassed across orm-loader:merge_replace/merge_insert/merge_upsertbuilt raw, unqualifiedtext()SQL; staging-tableindex inspection used a schema-blind
sa.inspect(); materialized-view lifecycle methods took ahand-threaded
schemastring instead of resolving through the connection; and a staging-tablereflection path could open a second connection that, on SQLite, silently discarded a session's own
uncommitted work.
Fix
Loaded/merged data
merge_replace/merge_insert/merge_upsertrewritten against realTableobjects anddialect-specific Core constructs (
sa.delete,insert().from_select(),postgresql.insert().on_conflict_do_nothing(), with a SQLite-specific counterpart), for bothbackends.
isolation_level="AUTOCOMMIT"call site.connection()instead of opening a second one off the bare engine — on SQLite'sSingletonThreadPoolthat second connection is the same underlying DBAPI connection, and closingit silently discarded the session's own uncommitted work.
_target_has_rows()simplified: dropped a dead cross-table re-reflection branch.Materialized views
create_mv/refresh_mv/drop_mv/index creation are fully role-aware: each resolves its physicalschema from the bound connection's own
schema_translate_map(__mv_role__, defaulting toRole.PRIMARY), not a hand-threadedschemaparameter._as_connection()context manager (every bind-taking backend method routes through it), replacing a narrower
per-method check that only ever guarded direct/manual
PostgresBackend()construction.manage_indices) now resolves itsInspectorschema-aware, viaschema_inspect(session, role=role_of_table(cls.__table__)).role_of_table()helper: reads a mapped table's own declared schema tag back as aRole.Split primary/vocab connections
(different engines, potentially different dialects), not just role-tagged schemas on one shared
connection.
Config, CI, test infrastructure
STAGING_SCHEMA's reserved-schema registration moved intoconfig.py(the actualomop.configentry point), so it's guaranteed to run whenever this package's config is resolvable, instead of
depending on some other module happening to be imported first.
OrmLoaderConfig.test_orm_dbsplit intotest_orm_db_pg/test_orm_db_sqlite, so dialect-specificintegration tests always run against the right kind of database regardless of local config.
engine_with_replica_rolenow usesautocommit_connection()'sEnginebranch directly instead ofopening a connection first and handing it in, removing a redundant step.
Dialectenum is gone; imports the shared one fromoa-configuratorinstead, with nochange in dispatch behaviour.
oa-configurator's new test infrastructure (isolated_test_database,DIALECT_PARAMS,the
db_dialectmarker).test_schema_translate_map.py(the actual regression test for the originally-reportedbug),
test_split_connection.py,test_shared_backend.py(merge-method contract tests unifiedacross both dialects),
test_reserved_schema.py(provesSTAGING_SCHEMAregistration is actuallyenforced cross-package, not just declared).
Checklist
breaking,feature,fix,dependencies, orchore)uv run pytest -q): 246 passed, 1 xfaileduv run pytest -q -m postgresql): 37 passeduv run ruff check .)