Skip to content

Comments

Workaround for importing ScalarAttributeImpl on SQLA2.1#804

Closed
Dev-iL wants to merge 1 commit intokvesteri:masterfrom
Dev-iL:patch-2
Closed

Workaround for importing ScalarAttributeImpl on SQLA2.1#804
Dev-iL wants to merge 1 commit intokvesteri:masterfrom
Dev-iL:patch-2

Conversation

@Dev-iL
Copy link
Contributor

@Dev-iL Dev-iL commented Jan 30, 2026

Handle the below by disabling the GenericAttributeImpl class on SQLA2.1:

.../sqlalchemy_utils/generic.py:15: in <module>
    class GenericAttributeImpl(attributes.ScalarAttributeImpl):
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AttributeError: module 'sqlalchemy.orm.attributes' has no attribute 'ScalarAttributeImpl'

Note: although it looks like a lot has changed, this PR only adds ~10 lines and the rest are indentation changes.

Related #800, #803

@kurtmckee
Copy link
Collaborator

@Dev-iL It looks like sqlalchemy has an example that we should probably be following (and that base example appears to have existed in sqlalchemy 1.4 as well).

I think that instead of causing this to fail on new versions of sqlalchemy, this PR should instead migrate the code to incorporate the example that sqlalchemy has defined.

From the maintainers of sqlalchemy --

Casey: apparently they define a so called generic_relationship. I don't know what it does

zzzeek: it's probably what we have here: https://docs.sqlalchemy.org/en/20/_modules/examples/generic_associations/generic_fk.html

but I really would have preferred they didnt make their own attribute impl

I'm closing this PR because it causes an outright failure on new versions of sqlalchemy instead of migrating the code to supported usage.

@kurtmckee kurtmckee closed this Jan 30, 2026
@Dev-iL
Copy link
Contributor Author

Dev-iL commented Jan 31, 2026

I'm closing this PR because it causes an outright failure on new versions of sqlalchemy instead of migrating the code to supported usage.

The failure is already present. The suggested workaround turns the import-time error, into a runtime error. In other words, on SQLA2.1 sqlalchemy-utils can't even be imported at the moment since the broken import happens at the top level __init__.py. With the suggested modification, if the user doesn't need the disabled functionality at least they can use everything else.

I think it is a suitable solution as a temporary measure until the "proper" way that you mentioned is implemented. Of course it wouldn't hurt to mention this behavior explicitly in the docs.

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.

2 participants