python-gino / gino

GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
https://python-gino.org/
Other
2.67k stars 150 forks source link

AttributeError: module 'sqlalchemy.sql.schema' has no attribute '_schema_getter' #769

Closed zillionare closed 3 years ago

zillionare commented 3 years ago

Describe the bug when import gino, it throws exception:

Traceback (most recent call last):
  File "/usr/local/bin/omega", line 5, in <module>
    from omega.cli import main
  File "/usr/local/lib/python3.8/dist-packages/omega/cli.py", line 25, in <module>
    import omicron
  File "/usr/local/lib/python3.8/dist-packages/omicron/__init__.py", line 6, in <module>
    import gino
  File "/usr/local/lib/python3.8/dist-packages/gino/__init__.py", line 2, in <module>
    from .engine import GinoEngine, GinoConnection  # NOQA
  File "/usr/local/lib/python3.8/dist-packages/gino/engine.py", line 181, in <module>
    class GinoConnection:
  File "/usr/local/lib/python3.8/dist-packages/gino/engine.py", line 211, in GinoConnection
    schema_for_object = schema._schema_getter(None)
AttributeError: module 'sqlalchemy.sql.schema' has no attribute '_schema_getter

To Reproduce I don't know what's exactly condition. It works before, just broken lately.

import gino

Environment (please complete the following information):

Additional context This is a service runs in a docker container, depends to postgres:10 images. the docker-compose file works days ago, don't know why it suddenly don't work. No change to my service executable, and I try to install them out of docker container, it works.

zillionare commented 3 years ago

I add print(dir(schema)) before line 211, and got the output:

['BLANK_SCHEMA', 'CheckConstraint', 'ClauseElement', 'Column', 'ColumnClause', 'ColumnCollectionConstraint', 'ColumnCollectionMixin', 'ColumnDefault', 'ColumnElement', 'Computed', 'Constraint', 'DEFAULT_NAMING_CONVENTION', 'DedupeColumnCollection', 'DefaultClause', 'DefaultGenerator', 'DialectKWArgs', 'FetchedValue', 'ForeignKey', 'ForeignKeyConstraint', 'Identity', 'IdentityOptions', 'Index', 'InternalTraversal', 'MetaData', 'NULL_UNSPECIFIED', 'PrimaryKeyConstraint', 'RETAIN_SCHEMA', 'SchemaEventTarget', 'SchemaItem', 'Sequence', 'Table', 'TableClause', 'TextClause', 'ThreadLocalMetaData', 'UniqueConstraint', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec', '_bind_or_error', '_copy_expression', '_document_text_coercion', '_get_table_key', 'absolute_import', 'coercions', 'collections', 'ddl', 'event', 'exc', 'inspection', 'quoted_name', 'roles', 'sqlalchemy', 'to_instance', 'type_api', 'util', 'visitors']

doesn't contains _schema_getter

zillionare commented 3 years ago

after I enter into the container, and run pip3 freeze |grep 'SQLAlchemy`, it's surprise that the version is 1.4.1. After rollback the version to 1.3.23, the exception disappear.

install 1.4.1 again, the error appears.

so this is an issue of version.

Please have SQLAlchemy's version locked.

wwwjfy commented 3 years ago

SQLAlchemy's version is defined to be <1.4 here https://github.com/python-gino/gino/blob/master/pyproject.toml#L28 The restriction has been there. I suspect your other dependency doesn't limit it.

A clean install shows below

$ pip install gino
Collecting gino
  Using cached gino-1.0.1-py3-none-any.whl (49 kB)
Collecting asyncpg<1.0,>=0.18
  Using cached asyncpg-0.22.0.tar.gz (770 kB)
Collecting SQLAlchemy<1.4,>=1.2.16
  Using cached SQLAlchemy-1.3.23.tar.gz (6.3 MB)
Building wheels for collected packages: asyncpg, SQLAlchemy
  Building wheel for asyncpg (setup.py) ... done
  Created wheel for asyncpg: filename=asyncpg-0.22.0-cp39-cp39-macosx_11_0_x86_64.whl size=1242347 sha256=b785bce395a4ef8e26dec867855b7ff549839882f0ce9c481f55ced3c04c44c9
  Stored in directory: /Users/tony/Library/Caches/pip/wheels/15/2a/b2/03c1c00e4194fda753056a3913f38300ee9992f286fb1d4240
  Building wheel for SQLAlchemy (setup.py) ... done
  Created wheel for SQLAlchemy: filename=SQLAlchemy-1.3.23-cp39-cp39-macosx_11_0_x86_64.whl size=1213378 sha256=9ad0ed44ade36ad96309f5e442a8432a49baa8058212489d4ba9ee43f928cfc8
  Stored in directory: /Users/tony/Library/Caches/pip/wheels/01/dc/3d/de7017735f3161747b4dee9bdaff7dcaaf73abff49bb0c230f
Successfully built asyncpg SQLAlchemy
Installing collected packages: asyncpg, SQLAlchemy, gino
Successfully installed SQLAlchemy-1.3.23 asyncpg-0.22.0 gino-1.0.1
mikekeda commented 3 years ago

duplicate #765

zillionare commented 3 years ago

closed this issue, since Gino has declare the right dependancy.

Thanks for the quick reponse, great confidence with Gino ^_^