Wrong dependencies resolving for SQLAlchemy[postgresql_asyncpg]
- [x] I am on the latest Poetry version.
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption).
- OS version and name: MacOS 12.2.1 on Apple M1 chip
- Poetry version: 1.1.13
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/evgen231/1cda84fbf99b826f9ed611d969fdd01e
Issue
After installing SQLAlchemy with postgresql_asyncpg extra there is no greenlet dependency.
# poetry update
Creating virtualenv example-OWA4dUH3-py3.9 in /Users/.../Library/Caches/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing asyncpg (0.25.0)
• Installing sqlalchemy (1.4.35)
# poetry run pip freeze
asyncpg @ .../asyncpg-0.25.0.tar.gz
SQLAlchemy @ .../SQLAlchemy-1.4.35.tar.gz
Using pip:
# python -m pip install 'sqlalchemy[postgresql_asyncpg]'
...
# python -m pip freeze
asyncpg==0.25.0
greenlet==1.1.2
SQLAlchemy==1.4.35
Same thing with poetry 1.2.0b1.
Hey @evgen231,
sqlalchemy has this marker for greenlet:
greenlet != 0.4.17;python_version>='3' and (platform_machine=='aarch64' or (platform_machine=='ppc64le' or (platform_machine=='x86_64' or (platform_machine=='amd64' or (platform_machine=='AMD64' or (platform_machine=='win32' or platform_machine=='WIN32'))))))
So my guess is, that your platform is not included here and it is intended that greenlet should not be installed.
fin swimmer
But pip does. So it's a bug in the pip and SQLAlchemy dependencies?
sqlalchemy[postgresql_asyncpg] has an unconditional dependency on greenlet, so it's a poetry bug.
cf https://github.com/sqlalchemy/sqlalchemy/issues/7714
I'm seeing the same with sqlalchemy[asyncio], which also includes greenlet (https://github.com/PrefectHQ/prefect/issues/6310).
The poetry.lock includes:
[[package]]
name = "sqlalchemy"
[package.dependencies]
greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"}
[package.extras]
asyncio = ["greenlet (!=0.4.17)"]
poetry show lists greenlet as a dependency:
❯ poetry show sqlalchemy
name : sqlalchemy
version : 1.4.40
description : Database Abstraction Library
dependencies
- greenlet !=0.4.17
Within a Poetry shell for the environment above, pip does not show the dependency:
❯ pip show sqlalchemy
Name: SQLAlchemy
Version: 1.4.40
Summary: Database Abstraction Library
Home-page: https://www.sqlalchemy.org
Author: Mike Bayer
Author-email: [email protected]
License: MIT
Location: /Users/lebovic/Library/Caches/pypoetry/virtualenvs/test-project-GQM6Mw9q-py3.8/lib/python3.8/site-packages
Requires:
Required-by: alembic, prefect
But when installed with pip instead of Poetry (via sqlalchemy[asyncio]), the greenlet dependency is installed:
❯ pip show sqlalchemy
Name: SQLAlchemy
Version: 1.4.40
Summary: Database Abstraction Library
Home-page: https://www.sqlalchemy.org
Author: Mike Bayer
Author-email: [email protected]
License: MIT
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: greenlet
Required-by: alembic, prefect
I have exact same problem with sqlalchemy[asyncio] and missing greenlet dependency, Poetry on M1
This is a currently unhandled edge case where an extra specifies an unconditional dependency that is excluded by 'base' markers.
sqlalchemy[asyncio] should be sufficient to work around this (or, manually specifying greenlet) until Poetry gains support.
I already have sqlalchemy[asyncio] ... I see greenlet in the lock file as a dependency but it does not get installed - this is the part that's not working
but explicitly adding greenlet via poetry add greenlet does fix it for me
PTAL @radoering @dimbleby when you have time, to confirm if my diagnosis is correct or not.
I don't see anything much to agree or disagree with...
Per this comment I do believe that it's a bug. I've a half-memory of taking a closer look back then and deciding that it was likely to be painful. But I haven't tried again and, you never know, maybe it'll turn out to be easy.
I'm quite sure that #7175 fixes this issue, but it wouldn't hurt if someone with a platform where the issue occurs could verify this.
@radoering issue does not appear to be resolved for me:
Poetry version: 1.6.1 Python version: 3.11.4 OS version and name: macOS Ventura 13.5.1
It is failing. ValueError: the greenlet library is required to use this function. No module named 'greenlet'
I have SQLALchemy specified like this in my pyproject.toml:
sqlalchemy = { version = "1.4.49", extras = ["postgresql_asyncpg"] }
I also tried with:
sqlalchemy = { version = "1.4.49", extras = ["asyncio"] }
Seems like this only works when I explicitly add greenlet as a dependency in pyproject.toml.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.