Repository navigation
Conversation
SQLAlchemy 2.1 made ScalarAttributeImpl and register_attribute private, breaking import of sqlalchemy_utils. Rather than depending on those internals, reimplement generic_relationship as a hybrid_property with a custom comparator, using only public APIs (object_session, Session.get, Mapper.get_property_by_column, registry.mappers, self_and_descendants). Assignment now goes through regular attribute instrumentation, so re-assigning a generic relationship on a persistent object is flushed. Also pin the test PostgreSQL DSN to psycopg2 since 2.1 changed the default postgresql:// driver to psycopg (v3).
tonyskapunk
added a commit
to distributedci/dci-control-server
that referenced
this pull request
Sep 28, 2026
SQLAlchemy-Utils does not have support for SQLAlchemy v2.1 yet causing issues while importing kvesteri/sqlalchemy-utils#829 kvesteri/sqlalchemy-utils#800 Should be solved by: kvesteri/sqlalchemy-utils#831 SQLAlchemy on 2.1 is causing this issue during db init: Traceback (most recent call last): File "/opt/dci-control-server/bin/dci-dbinit", line 27, in <module> from sqlalchemy_utils import functions as sa_funcs File "/usr/local/lib/python3.12/site-packages/sqlalchemy_utils/__init__.py", line 46, in <module> from .generic import generic_relationship # noqa ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy_utils/generic.py", line 15, in <module> class GenericAttributeImpl(attributes.ScalarAttributeImpl): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'sqlalchemy.orm.attributes' has no attribute 'ScalarAttributeImpl'. Did you mean: '_ScalarAttributeImpl'? Unable to init the DB. Exiting.
tiborsimko
added a commit
to tiborsimko/reana-db
that referenced
this pull request
Sep 30, 2026
SQLAlchemy-Utils 0.41.2 imports ScalarAttributeImpl, which was made private in SQLAlchemy 2.1. This prevents REANA database consumers from starting despite passing pip check. Keep SQLAlchemy on the compatible 2.0 series until the upstream fix is released and validated. See kvesteri/sqlalchemy-utils#831
This was referenced Oct 5, 2026
Author
|
Hi @kurtmckee Just wondering if you could take a look at this one? The previous was rejected quite swiftly, really hoping we can get a release out that supports 2.1. |
tobias-urdin
added a commit
to gnocchixyz/gnocchi
that referenced
this pull request
Oct 5, 2026
SQLAlchemy 2.1 has breaking changes that are not yet supported in sqlalchemy-utils [1]. [1] kvesteri/sqlalchemy-utils#831 Change-Id: I67afc2f8199b12823a85a07b05170f7d48da8bb6 Signed-off-by: Tobias Urdin <tobias.urdin@binero.com>
tobias-urdin
added a commit
to gnocchixyz/gnocchi
that referenced
this pull request
Oct 5, 2026
SQLAlchemy 2.1 has breaking changes that are not yet supported in sqlalchemy-utils [1]. [1] kvesteri/sqlalchemy-utils#831 Change-Id: I3b1854519e7897a54b95e376cd2d7d83b99d409c Signed-off-by: Tobias Urdin <tobias.urdin@binero.com>
tobias-urdin
added a commit
to gnocchixyz/gnocchi
that referenced
this pull request
Oct 5, 2026
SQLAlchemy 2.1 has breaking changes that are not yet supported in sqlalchemy-utils [1]. [1] kvesteri/sqlalchemy-utils#831 Change-Id: Ia0bea063118d0026e7cdbd2a9c01560aeda46373 Signed-off-by: Tobias Urdin <tobias.urdin@binero.com>
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.
Follow-up to #830, reworked based on the feedback there: this no longer touches any SQLAlchemy internals.
Summary
import sqlalchemy_utilsfails on SQLAlchemy 2.1:The only user of those internals was
generic_relationship. Rather than importing the now-private_ScalarAttributeImpl/_register_attribute, this PR reimplements it as ahybrid_propertywith a custom comparator, using only public APIs:object_session()+Session.get()(replaces the private_state_session).inspect(cls).registry.mappers(replacesregistry._class_registry).Mapper.get_property_by_column().is_type()viaMapper.self_and_descendants(replaces_inheriting_mappers).GenericAttributeImplconstructor version-sniffing hack is gone.The public interface is unchanged:
generic_relationship(discriminator, id, doc=None), column/string/hybrid discriminators, composite ids,declared_attron abstract bases,Event(object=obj),filter_by(object=obj),Event.object == obj,!=, andis_type().Behaviour changes
Event.objectis a hybrid rather than aMapperProperty, so it appears inmapper.all_orm_descriptorsbut notmapper.attrs.ImproperlyConfiguredon first use rather than at mapper configuration.Tests
Also pins the test PostgreSQL DSN to
postgresql+psycopg2://. SQLAlchemy 2.1 changed the defaultpostgresql://driver to psycopg (v3), whichCompositeTypedoesn't support.Testing
tests/generic_relationshiptests pass on SQLAlchemy 2.0.54 and 2.1.0.select().where(Event.object == obj),is_type(), anddoc=.Notes
CompositeTypestill only supports psycopg2; on 2.1, a plainpostgresql://URL gets psycopg3. psycopg3 support could be a follow-up.