snowflakedb / snowflake-sqlalchemy

Snowflake SQLAlchemy
https://pypi.python.org/pypi/snowflake-sqlalchemy/
Apache License 2.0
235 stars 152 forks source link

SNOW-1324105: ImportError: cannot import name 'string_types' from 'sqlalchemy.util.compat' due to latest SQLAlchemy version #485

Closed sshah90 closed 7 months ago

sshah90 commented 7 months ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

    3.10

  2. What operating system and processor architecture are you using?

    macOS-14.4.1-x86_64-i386-64bit

  3. What are the component versions in the environment (pip freeze)?

I created brand new virtual environments and install snowflake-sqlalchemy

asn1crypto==1.5.1
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.5
filelock==3.13.4
greenlet==3.0.3
idna==3.7
packaging==24.0
platformdirs==4.2.0
pycparser==2.22
PyJWT==2.8.0
pyOpenSSL==24.1.0
pytz==2024.1
requests==2.31.0
snowflake-connector-python==3.8.1
snowflake-sqlalchemy==1.5.2
sortedcontainers==2.4.0
**SQLAlchemy==2.0.29**
tomlkit==0.12.4
typing_extensions==4.11.0
urllib3==2.2.1
  1. What did you do? I installed newest version of snowflake-sqlalchemy v1.5.2 which brings SQLAlchemy==2.0.29 which causing import errors.

With v1.5.1, it's working fine.

I ran below import command

from snowflake.sqlalchemy import URL

I got below Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/##/Desktop/python-virtual/poetry-test/lib/python3.10/site-packages/snowflake/sqlalchemy/__init__.py", line 30, in <module>
    from . import base, snowdialect
  File "/Users/##/Desktop/python-virtual/poetry-test/lib/python3.10/site-packages/snowflake/sqlalchemy/base.py", line 20, in <module>
    from sqlalchemy.util.compat import string_types
ImportError: cannot import name 'string_types' from 'sqlalchemy.util.compat' (/Users/###/Desktop/python-virtual/poetry-test/lib/python3.10/site-packages/sqlalchemy/util/compat.py)

Do we need to lock dependency at pyproject.toml ?

  1. What did you expect to see?

    It should be able to import URL without any failures.

jessfreedom commented 7 months ago

running into same issue with Python 3.11.6, macOS-14.4.1 M2 Pro asn1crypto==1.5.1 Cerberus==1.3.5 certifi==2024.2.2 cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 click-default-group==1.2.4 colorama==0.4.6 coloredlogs==15.0.1 cryptography==42.0.5 filelock==3.13.4 humanfriendly==10.0 idna==3.7 importlib_metadata==7.1.0 jaraco.classes==3.4.0 keyring==24.3.1 more-itertools==10.2.0 packaging==24.0 permifrost==0.15.4 platformdirs==4.2.0 pycparser==2.22 PyJWT==2.8.0 pyOpenSSL==24.1.0 pytz==2024.1 PyYAML==6.0.1 requests==2.31.0 snowflake-connector-python==3.8.1 snowflake-sqlalchemy==1.5.2 sortedcontainers==2.4.0 SQLAlchemy==2.0.29 tomlkit==0.12.4 typing_extensions==4.11.0 urllib3==2.2.1 zipp==3.18.1

cboulanger23 commented 7 months ago

Same issue trying to use Django 4.2 + django-snowflake 4.2 which has a dependency on snowflake-sqlalchemy (~=1.5.x). Reverting snowflake-sqlalchemy version 1.5.2 to 1.5.1 fixed the issue. Python 3.8.13, x86_64, ubuntu 20.04

jessfreedom commented 7 months ago

Yeah, looks like there's something wrong with the latest version. Might be something to do with updating to using the latest version of sqlalchemy 2.0. Pinning to 1.5.1 worked - it's still using sqlalchemy 1.4.

aclemente-tkww commented 7 months ago

From a quick look, it seems like between versions, this package changed from specifying the dependencies with setup.cfg https://github.com/snowflakedb/snowflake-sqlalchemy/blob/61975bf607434fe8427aaae926549e8ffd3e9bb8/setup.cfg#L50

To using pyproject.toml + hatch https://github.com/snowflakedb/snowflake-sqlalchemy/blob/4db4b9521d42d43a6619bf5ca307e1eaa2c6aa09/pyproject.toml#L41 I am not familiar with hatch, but looks like there's a version requirement missing in the specifier. Either that, or this change was on purpose and we missed some announcement or doc. In any case, this does not seem like a change to do in a patch version.

sfc-gh-dszmolka commented 7 months ago

hi folks, thanks for reporting - yes definitely this is unexpected and not a planned change to go to sqlalchemy 2 in a patch version but rather a bug. We'll take a look.

sfc-gh-dszmolka commented 7 months ago

fix is https://github.com/snowflakedb/snowflake-sqlalchemy/pull/486 which is now merged. I'm reopening this issue to be able to properly track, because we need to release the next version which carries the fix

expected by latest April release cycle (end of month)

sfc-gh-dszmolka commented 7 months ago

fix released with v1.5.3