poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Wrong dependencies resolving for SQLAlchemy[postgresql_asyncpg]

Open evgen231 opened this issue 4 years ago • 6 comments

  • [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 (-vvv option).
  • 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

evgen231 avatar Apr 08 '22 07:04 evgen231

Same thing with poetry 1.2.0b1.

evgen231 avatar Apr 08 '22 07:04 evgen231

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

finswimmer avatar Apr 08 '22 19:04 finswimmer

But pip does. So it's a bug in the pip and SQLAlchemy dependencies?

evgen231 avatar Apr 08 '22 20:04 evgen231

sqlalchemy[postgresql_asyncpg] has an unconditional dependency on greenlet, so it's a poetry bug.

dimbleby avatar Apr 10 '22 23:04 dimbleby

cf https://github.com/sqlalchemy/sqlalchemy/issues/7714

dimbleby avatar Apr 10 '22 23:04 dimbleby

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

lebovic avatar Aug 09 '22 13:08 lebovic

I have exact same problem with sqlalchemy[asyncio] and missing greenlet dependency, Poetry on M1

anentropic avatar Sep 30 '22 10:09 anentropic

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.

neersighted avatar Sep 30 '22 12:09 neersighted

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

anentropic avatar Sep 30 '22 12:09 anentropic

PTAL @radoering @dimbleby when you have time, to confirm if my diagnosis is correct or not.

neersighted avatar Oct 02 '22 15:10 neersighted

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.

dimbleby avatar Oct 02 '22 16:10 dimbleby

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 avatar Dec 11 '22 16:12 radoering

@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.

phillipuniverse avatar Aug 24 '23 03:08 phillipuniverse

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.

github-actions[bot] avatar Feb 29 '24 08:02 github-actions[bot]