Skip to content

poetry-core crashes on platform_release != "x" and "y" not in platform_release #10978

Description

@notatallshaw

Description

I'm working on marker logic and doing a comparison of different libraries, while doing a scan of poetry, I found a couple of bugs.

Mixing the normal and swapped forms of a platform_release marker crashes parse_marker with AttributeError: 'Constraint' object has no attribute 'flatten'.

>>> from poetry.core.version.markers import parse_marker
>>> parse_marker('platform_release != "1" and "a" not in platform_release')
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    parse_marker('platform_release != "1" and "a" not in platform_release')
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1047, in parse_marker
    markers = _compact_markers(parsed.children)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1106, in _compact_markers
    return union(*sub_markers)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1156, in decorated
    result = func(*markers)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1202, in union
    conjunction = cnf(unnormalized)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1122, in cnf
    return MultiMarker.of(*[cnf(m) for m in marker.markers])
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 675, in of
    new_marker = mark.intersect(marker)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 318, in intersect
    merged = _merge_single_markers(self, other, MultiMarker)
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\version\markers.py", line 1253, in _merge_single_markers
    result_constraint = merge_method(marker2.constraint)  # type: ignore[arg-type]
  File "C:\Users\damia\AppData\Local\uv\cache\archive-v0\Xz3Y_BKecJLSBFHN\Lib\site-packages\poetry\core\constraints\version\version_union.py", line 142, in intersect
    their_ranges = iter(other.flatten())
                        ^^^^^^^^^^^^^
AttributeError: 'Constraint' object has no attribute 'flatten'

Workarounds

Don't use weird marker combinations, this is obscure, but that's because I'm doing a correctness analysis of all marker handling across the Python ecosystem.

Poetry Installation Method

other

Operating System

Windows 11 or Ubuntu 24.04 or Anything

Poetry Version

poetry-core 2.4.1

Poetry Configuration

I'm running all my tests via uvx so I think this isn't relevant but here you go:


Installed 41 packages in 362ms
cache-dir = "C:\\Users\\damia\\AppData\\Local\\pypoetry\\Cache"
data-dir = "C:\\Users\\damia\\AppData\\Roaming\\pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = false
keyring.enabled = true
python.installation-dir = "{data-dir}\\python"  # C:\Users\damia\AppData\Roaming\pypoetry\python
requests.max-retries = 0
solver.lazy-wheel = true
solver.min-release-age = 0
solver.min-release-age-exclude = null
solver.min-release-age-exclude-source = null
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"  # C:\Users\damia\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

sysconfig.log
Paste the output of 'python -m sysconfig', over this line.

Example pyproject.toml

Poetry Runtime Logs

poetry-runtime.log
Paste the output of 'poetry -vvv <command>', over this line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions