Skip to content

Conversation

@kurtmckee
Copy link
Collaborator

This patch introduces the following changes:

  • Enable sqlalchemy 2.0 compatibility warnings during unit testing.
  • Update the code, docstrings, and unit tests to support sqlalchemy 2.0 behavior and syntax.

Most of the warnings revolved around the following incompatibilities:

  • sqlalchemy 2.0 no longer auto-adds objects across backref relationships.
  • sqlalchemy 2.0 no longer auto-commits objects.
  • Raw SQL strings must always be wrapped in calls to sqlalchemy.text().
  • Query.get() calls must migrate to Session.get().
  • select() calls must use positional parameters and must use generative method calls instead of keyword arguments (e.g. select(..., fromobj=...) must become select(...).select_from(...)).

Closes #513.

@kurtmckee kurtmckee added the sqlalchemy sqlalchemy compatibility label Jun 17, 2022
@kurtmckee kurtmckee requested a review from kvesteri June 17, 2022 13:16
@kurtmckee kurtmckee self-assigned this Jun 17, 2022
@kurtmckee kurtmckee force-pushed the sqlalchemy-2.0-issue-513 branch from 2d0fcab to 6c3e7f7 Compare June 19, 2022 14:44
@kurtmckee
Copy link
Collaborator Author

Resolved merge conflicts

@kurtmckee kurtmckee merged commit 1f6e2d6 into master Jun 19, 2022
@kurtmckee kurtmckee deleted the sqlalchemy-2.0-issue-513 branch June 19, 2022 15:08
@whwright
Copy link

thank you for adding this! any plans to release a new version of sqlalchemy-utils to capture these changes?

@kurtmckee
Copy link
Collaborator Author

kurtmckee commented Jun 30, 2022

Tagging @kvesteri to review this question. 👀

@whwright you're welcome! It was definitely a learning experience! 😀

@kvesteri
Copy link
Owner

I uploaded new version to PyPi

@kurtmckee
Copy link
Collaborator Author

Thanks @kvesteri!

@mrlonis
Copy link

mrlonis commented Nov 16, 2022

I am unable to use this package with the beta releases of SQL Alchemy 2.0.

from sqlalchemy_utils import Ltree, LtreeType, force_auto_coercion
../../../../venvs/pkg-py-postgres-crud/lib/python3.10/site-packages/sqlalchemy_utils/__init__.py:59: in <module>
    from .types import (  # noqa
../../../../venvs/pkg-py-postgres-crud/lib/python3.10/site-packages/sqlalchemy_utils/types/__init__.py:42: in <module>
    from .uuid import UUIDType  # noqa
../../../../venvs/pkg-py-postgres-crud/lib/python3.10/site-packages/sqlalchemy_utils/types/uuid.py:8: in <module>
    sqlalchemy_version = tuple([int(v) for v in __version__.split(".")])
../../../../venvs/pkg-py-postgres-crud/lib/python3.10/site-packages/sqlalchemy_utils/types/uuid.py:8: in <listcomp>
    sqlalchemy_version = tuple([int(v) for v in __version__.split(".")])
E   ValueError: invalid literal for int() with base 10: '0b3'

Seems to be just a minor version check. I assume this is intentional? I was hoping to see how many things would break with the beta version and I can't tell because SQLAlchemy-Utils fails out

@kurtmckee
Copy link
Collaborator Author

@mrlonis This was fixed in #644 but there hasn't been a sqlalchemy-utils release that includes that fix yet.

I've received permissions to publish new sqlalchemy-utils releases but haven't had a chance to try publishing a new release. I'll try to get that done soon.

Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqlalchemy sqlalchemy compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for sqlalchemy 2.0

5 participants