Skip to content

Incorrect lock file when same dependencies (with same extras) is specified in multiple groups #10153

@bram-tv

Description

@bram-tv

Description

When a dependency with extras is specified in multiple optional groups then the poetry.lock file is incomplete/incorrect:

  • the extras are not included
  • the groups field does not include all the groups

Example pyproject.toml: (using [tool.poetry] and not [project] to be able to easily run with older poetry version)

[tool.poetry]
name = "example"
version = "0.0.0.0"
authors = ["[email protected]"]
description = ""

[tool.poetry.dependencies]
python = ">=3.7"
exceptiongroup = "1.2.2"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
exceptiongroup = {version = "1.2.2", extras = ["test"]}

[tool.poetry.group.test]
optional = true

[tool.poetry.group.test.dependencies]
exceptiongroup = {version = "1.2.2", extras = ["test"]}

Creating the lock file using poetry 2.0.1:

...
Resolving dependencies...
   1: fact: example is 0.0.0.0
   1: derived: example
   0: Duplicate dependencies for exceptiongroup
   1: fact: example depends on exceptiongroup (1.2.2)
   1: fact: example depends on exceptiongroup (1.2.2)
   1: selecting example (0.0.0.0)
   1: derived: exceptiongroup (==1.2.2)
   1: selecting exceptiongroup (1.2.2)
   1: Version solving took 0.006 seconds.
   1: Tried 1 solutions.

Complete poetry.lock file:

# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand.

[[package]]
name = "exceptiongroup"
version = "1.2.2"
description = "Backport of PEP 654 (exception groups)"
optional = false
python-versions = ">=3.7"
groups = ["main"]
files = [
    {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"},
    {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"},
]

[package.extras]
test = ["pytest (>=6)"]

[metadata]
lock-version = "2.1"
python-versions = ">=3.7"
content-hash = "ecabace2ad7e16417874f4635aa6e9eda00e317d93bfe111615c86f108483f7f"

Result:

  • The extras dependencies are not included/locked
  • groups only includes main but it should also include dev and test
Altering tpyproject.toml and removing the test group
[tool.poetry]
name = "example"
version = "0.0.0.0"
authors = ["[email protected]"]
description = ""

[tool.poetry.dependencies]
python = ">=3.7"
exceptiongroup = "1.2.2"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
exceptiongroup = {version = "1.2.2", extras = ["test"]}

And running lock again:

Resolving dependencies...
Updating dependencies
Resolving dependencies...
   1: fact: example is 0.0.0.0
   1: derived: example
   0: Duplicate dependencies for exceptiongroup
   1: fact: example depends on exceptiongroup (1.2.2)
   1: fact: example depends on exceptiongroup[test] (1.2.2)
   1: selecting example (0.0.0.0)
   1: derived: exceptiongroup[test] (==1.2.2)
   1: derived: exceptiongroup (==1.2.2)
   1: fact: exceptiongroup[test] (1.2.2) depends on exceptiongroup (1.2.2)
   1: fact: exceptiongroup[test] (1.2.2) depends on pytest (>=6)
   1: selecting exceptiongroup[test] (1.2.2)
   1: derived: pytest (>=6)
    ....

poetry.lock file (stripped):

# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand.

...
[[package]]
name = "exceptiongroup"
version = "1.2.2"
description = "Backport of PEP 654 (exception groups)"
optional = false
python-versions = ">=3.7"
groups = ["main", "dev"]
files = [
    {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"},
    {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"},
]

[package.dependencies]
pytest = {version = ">=6", optional = true, markers = "extra == \"test\""}

[package.extras]
test = ["pytest (>=6)"]

...

[[package]]
name = "pytest"
version = "7.4.4"
description = "pytest: simple powerful testing with Python"
optional = false
python-versions = ">=3.7"
groups = ["dev"]
files = [
    {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"},
    {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"},
]

[package.dependencies]
colorama = {version = "*", markers = "sys_platform == \"win32\""}
exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""}
importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""}
iniconfig = "*"
packaging = "*"
pluggy = ">=0.12,<2.0"
tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}

[package.extras]
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]

...

[metadata]
lock-version = "2.1"
python-versions = ">=3.7"
content-hash = "2808730e2d4e12377583233f375a6fa0449d81eda483a141c4014af159de1fb0"

Result:

  • The extras dependencies are included/locked
  • groups includes main and dev

Workarounds

Use poetry < 2.0.0

Poetry Installation Method

pip

Operating System

Debian

Poetry Version

Poetry (version 2.0.1)

Poetry Configuration

cache-dir = "..../.cache/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /......./.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/solverRelated to the dependency resolverkind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions