Skip to content

[v8] fix SQLAlchemy 2.1 incompatibility in InstalledComponentsDB - #8855

Merged
fstagni merged 5 commits into
DIRACGrid:rel-v8r0from
fstagni:fix/sqlalchemy-21-rel-v8r0
Oct 26, 2026
Merged

fstagni merged 5 commits into
DIRACGrid:rel-v8r0from
fstagni:fix/sqlalchemy-21-rel-v8r0

Conversation

@fstagni

@fstagni fstagni commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Backports to rel-v8r0 of the SQLAlchemy 2.x compatibility fixes already merged into rel-v9r0 via #8561:

  • fix: avoid using text — rewrites InstalledComponentsDB to use ORM expressions instead of building raw SQL strings (removes session.execute(<legacy Query>), which SQLAlchemy 2.1 rejects, and removes the SQL-injection-prone f-string text() filters)
  • fix: use object properties directly — replaces the remaining text(Column.attr == value) calls

Both cherry-picked without conflicts.

Context: conda-forge published SQLAlchemy 2.1.0 on 2026-09-25. The DIRACOS2 installer builds with sqlalchemy >=1.4.36 (no upper bound), so installers built since then ship SQLAlchemy 2.1.x and the DIRACOS2 Integration tests (Py3 server) (rel-v8r0) job has been failing on every run since (e.g. DIRACOS2#204 and main's scheduled runs). rel-v9r0 and integration pass because they already contain these fixes.

-    filteredTemp = filtered.filter(text(sql))
-    try:
-        session.execute(filteredTemp)
-        session.commit()
-    except Exception as e:
-        return S_ERROR(f"Could not filter the fields: {e}")
-    filtered = filteredTemp
+    filtered = filtered.filter(column == value)   # ORM expressions

Evidence

Local repro against SQLAlchemy 2.1.6 (same version the failing CI installer resolves), driving the real InstalledComponentsDB with an in-memory engine:

Before backport:
componentExists:        ERROR ... expected string or bytes-like object, got 'BinaryExpression'
getComponents:          ERROR Could not filter the fields: Not an executable object: <Query ...>
getHosts:               ERROR Could not filter the fields: Not an executable object: <Query ...>
addInstalledComponent:  ERROR Could not filter the fields: Not an executable object: <Query ...>   <- exact CI failure

After backport:
all calls OK, on both SQLAlchemy 2.0.52 and 2.1.6

Merge Danger

Door: two-way (revertable cherry-picks; no schema or API changes)

Blast Radius: InstalledComponentsDB / ComponentMonitoring on DIRAC v8 installations. Once merged, DIRACOS2's rel-v8r0 integration job (installed from the rel-v8r0 branch) should go green again.

@fstagni fstagni added the sweep:ignore Prevent sweeping from being ran for this PR label Oct 26, 2026
@fstagni
fstagni merged commit b1640ec into DIRACGrid:rel-v8r0 Oct 26, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sweep:ignore Prevent sweeping from being ran for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants