You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'EmptyConstraint' object has no attribute 'min' with pytest and Python 2.7 #3862
I've discovered a bug that arises when pytest is combined with Python ^2.7 in pyproject.toml. The Gist linked above provides a minimal example of this issue. Running poetry lock with the above file results in the following exception:
AttributeError
'EmptyConstraint' object has no attribute 'min'
The error does not appear if either pytest is removed or the Python version is changed to ^3.6. I originally reported this as part of #2372, but then realized that that issue related to error handing in response to an error in pyproject.toml. As this error occurs in a correctly-formatted pyproject.toml, I believe it is a distinct issue.
We started seeing this same error yesterday as well. I'm guessing some dependency in the tree did a release recently that is somehow exposing this bug.
After some debugging I think I narrowed down the problem to a recent backports.functools-lru-cache package release. Changing the dev-deps to this still reproduces the problem:
Experiencing the same thing with python = "^3.6". I tried adding "backports.functools-lru-cache" = "1.6.1" to my deps or dev-deps, but it didn't solve the issue. You can see the failure on this CI pipeline.
My suspicion is that there might be another dependency out in the wild that also exposes the bug. If you can get poetry onto a debugger that's how I found out that the lru-cache package was causing issues.
@pawamoy I did some digging and the issue you're seeing is from backports.entry_points_selectable. Unfortunately it looks like there is no release to pin back to, the very first release has the same problematic line as the other backports module I mentioned above. I think the only way to work around this one would be to find what's depending on this backports package and pin that instead.
Of course, all of this is just workarounds. It's still fundamentally a bug in poetry that can't seem to handle this dependency line:
pytest-mypy; python_implementation != "PyPy" and python_version < "3.10" and python_version > "3"
I wonder if pytest-mypy; python_implementation != "PyPy" and python_version < "3.10" and python_version > "3" is valid though:
> "3" suggests strictly higher than version 3, and Poetry deduces >=4, which seems correct to me?
then < "3.10" makes it impossible
Poetry should maybe simply catch the AttributeError to re-raise an InvalidMarker exception that will make the parent function try again without the markers, or re-raise a ValueError instead, making it skip this dependency.
try:
# Attempt to parse the PEP-508 requirement stringdependency=dependency_from_pep_508(req, relative_to=root_dir)
exceptInvalidMarker:
# Invalid marker, We strip the markers hoping for the bestreq=req.split(";")[0]
dependency=dependency_from_pep_508(req, relative_to=root_dir)
exceptValueError:
# Likely unable to parse constraint so we skip itself._log(
"Invalid constraint ({}) found in {}-{} dependencies, ""skipping".format(req, package.name, package.version),
level="warning",
)
continue
> "3" could also be understood as > "3.0", in which case the inequality makes sense so perhaps that was the intent? I agree >= "3" makes more sense, though.
I've identified the package who recently released a new version depending on backports.entry_points_selectable: pytest-randomly v3.6.0: pytest-dev/pytest-randomly@3.5.0...3.6.0 (look at requirements.in)
I was able to fix that issue in CI with the following hack:
- name: Set up Poetry# HACK: https://github.com/python-poetry/poetry-core/pull/154run: | pip install git+https://github.com/python-poetry/poetry pip uninstall -y poetry-core pip install git+https://github.com/pbzweihander/poetry-core@resolve-invalid-python-version-constraint
But I guess I should simply downgrade and pin pytest-randomly to 3.5.0 🙂
Activity
JennToo commentedon Mar 31, 2021
We started seeing this same error yesterday as well. I'm guessing some dependency in the tree did a release recently that is somehow exposing this bug.
JennToo commentedon Mar 31, 2021
After some debugging I think I narrowed down the problem to a recent backports.functools-lru-cache package release. Changing the dev-deps to this still reproduces the problem:
As a temporary workaround, you can pin this dependency back like this:
poetry seems to be tripping up on this line from their
setup.cfg:nikmolnar commentedon Mar 31, 2021
Thanks for the workaround, @Nitori- !
pawamoy commentedon Apr 1, 2021
Experiencing the same thing with
python = "^3.6". I tried adding"backports.functools-lru-cache" = "1.6.1"to my deps or dev-deps, but it didn't solve the issue. You can see the failure on this CI pipeline.JennToo commentedon Apr 1, 2021
My suspicion is that there might be another dependency out in the wild that also exposes the bug. If you can get poetry onto a debugger that's how I found out that the lru-cache package was causing issues.
pawamoy commentedon Apr 1, 2021
I patched Poetry's source to catch the exception and print the package name:
~/.local/pipx/venvs/poetry/lib/python3.9/site-packages/poetry/core/packages/__init__.pyline 219The output showed
pytest-mypy. Oh well I see now it was mentioned in your comments 😩JennToo commentedon Apr 1, 2021
If you jump up maybe 2-3 stacks, you'll see the package that was depending on pytest-mypy. That's probably the one that needs to get pinned.
JennToo commentedon Apr 2, 2021
@pawamoy I did some digging and the issue you're seeing is from
backports.entry_points_selectable. Unfortunately it looks like there is no release to pin back to, the very first release has the same problematic line as the other backports module I mentioned above. I think the only way to work around this one would be to find what's depending on this backports package and pin that instead.Of course, all of this is just workarounds. It's still fundamentally a bug in poetry that can't seem to handle this dependency line:
pawamoy commentedon Apr 2, 2021
Damn, I can't work on any project now, nothing will resolve 😅
I'll have to debug this first! Thanks a lot for your help @Nitori-!
pawamoy commentedon Apr 2, 2021
I wonder if
pytest-mypy; python_implementation != "PyPy" and python_version < "3.10" and python_version > "3"is valid though:> "3"suggests strictly higher than version 3, and Poetry deduces>=4, which seems correct to me?< "3.10"makes it impossiblePoetry should maybe simply catch the
AttributeErrorto re-raise anInvalidMarkerexception that will make the parent function try again without the markers, or re-raise aValueErrorinstead, making it skip this dependency.dkasak commentedon Apr 2, 2021
> "3"could also be understood as> "3.0", in which case the inequality makes sense so perhaps that was the intent? I agree>= "3"makes more sense, though.pawamoy commentedon Apr 2, 2021
@dkasak maybe! However I think it's parsed as precision 1, entering this condition:
(and so it's changing it to
>=with the next major version, which is 4)I guess we'll need to read the spec to decide if it's correct or not!
pawamoy commentedon Apr 2, 2021
OK, PEP508 says versions comparison is done according to PEP440.
pawamoy commentedon Apr 2, 2021
And using PEP440 version parsing, it seems Poetry should not consider
>3to be>=4sincepawamoy commentedon Apr 2, 2021
Poetry core has a 1.1.0a1 release that refactored all this, I'll try it and report back.
UPDATE: well no, it suffers from the exact same issue.
pawamoy commentedon Apr 2, 2021
Ah, there's a related PR python-poetry/poetry-core#154
pawamoy commentedon Apr 2, 2021
I've identified the package who recently released a new version depending on backports.entry_points_selectable: pytest-randomly v3.6.0: pytest-dev/pytest-randomly@3.5.0...3.6.0 (look at requirements.in)
I was able to fix that issue in CI with the following hack:
But I guess I should simply downgrade and pin pytest-randomly to 3.5.0 🙂
ci: Temporary fix
nikmolnar commentedon Apr 3, 2021
Thanks for the quick work on this, @sdispater et. al!
sobolevn commentedon Apr 4, 2021
I would love to see this fix released, as it hits me really hard in all (>50) of my projects.
backports.entry_points_selectable: Autospec creation for update from …
py-backports.functools_lru_cache: updated to 1.6.4
github-actions commentedon Mar 2, 2024
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.