Skip to content

'EmptyConstraint' object has no attribute 'allows' #4402

Closed
python-poetry/poetry-core
#188

Description

@asifali22

Everything was working fine until yesterday, I cleaned up my docker ending up removing all the images, etc. The project was building fine before clean up. Post clean up when I rebuilt the docker image, I started receiving the error:

 Writing lock file
#11 68.00
#11 68.00 [AttributeError]
#11 68.00 'EmptyConstraint' object has no attribute 'allows'
#11 68.00
#11 68.05 Traceback (most recent call last):
#11 68.05   File "/usr/local/lib/python3.8/site-packages/clikit/console_application.py", line 131, in run
#11 68.05     status_code = command.handle(parsed_args, io)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/clikit/api/command/command.py", line 120, in handle
#11 68.05     status_code = self._do_handle(args, io)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/clikit/api/command/command.py", line 171, in _do_handle
#11 68.05     return getattr(handler, handler_method)(args, io, self)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/cleo/commands/command.py", line 92, in wrap_handle
#11 68.05     return self.handle()
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/console/commands/update.py", line 49, in handle
#11 68.05     return installer.run()
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/installation/installer.py", line 74, in run
#11 68.05     self._do_install(local_repo)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/installation/installer.py", line 230, in _do_install
#11 68.05     self._filter_operations(ops, local_repo)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/installation/installer.py", line 447, in _filter_operations
#11 68.05     ) or not self._env.is_valid_for_marker(package.marker):
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/utils/env.py", line 808, in is_valid_for_marker
#11 68.05     return marker.validate(self.marker_env)
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/version/markers.py", line 601, in validate
#11 68.05     if m.validate(environment):
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/version/markers.py", line 470, in validate
#11 68.05     if not m.validate(environment):
#11 68.05   File "/usr/local/lib/python3.8/site-packages/poetry/version/markers.py", line 361, in validate
#11 68.05     return self._constraint.allows(self._parser(environment[self._name]))
#11 68.05

Here's my .toml file:

[tool.poetry]
name = "myproject"
version = "0.1.0"
description = ""
authors = ["abc <abc@mail.in>"]

[tool.poetry.dependencies]
python = "^3.8"
python-dotenv = "^0.17.0"
numpy = ">=1.19.2"
pandas = "^1.2.4"
Flask = "^1.1.2"
Flask-SQLAlchemy = "^2.5.1"
Flask-Migrate = "^2.7.0"
newrelic = "^6.2.0"
python-jose = "^3.2.0"
Flask-JWT = "^0.3.2"
PyMySQL = "^1.0.2"
psycopg2 = "^2.8.6"
toolz = "^0.11.1"
sortedcontainers = "^2.3.0"
sqlalchemy-redshift = "^0.8.2"
boto3 = "^1.17.57"
joblib = "^1.0.1"
xgboost = "^1.4.2"
scikit-learn = "^0.24.2"
redis = "^3.5.3"
celery = {extras = ["redis"], version = "^5.1.0"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

And here's my dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.8

LABEL MAINTAINER="test@mail.in>"

ARG APP_DIR=/zest-srv
ARG SERVICE_NAME=service
ARG LOG_DIR_PATH=/var/log/uwsgi

WORKDIR $APP_DIR

RUN apt-get update \
     && apt-get install -y ca-certificates

ARG POETRY_VERSION=1.0.0

## Use this instead
# curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

RUN pip install poetry==$POETRY_VERSION
RUN poetry --version
COPY poetry.lock pyproject.toml ${APP_DIR}/
RUN poetry update -vvv

# RUN mkdir ${APP_DIR}/lib
# COPY lib/transportstore-0.1.0-py3-none-any.whl ${APP_DIR}/lib/

RUN poetry config virtualenvs.create false \
    && poetry install --no-interaction --no-ansi

Here the debug logs: https://pastebin.com/sbiiDf8Z

Activity

  1. s3rius commented on Aug 19, 2021

    @s3rius

    I faced the same issue. My problem was that I was using SQLAlchemy with version "^1.4".
    But yesterday SQLAlchemy released "1.4.23" with platform_machine constraint.

    Here's the link: https://github.com/sqlalchemy/sqlalchemy/blob/4331c1902ae341158b597769f4e4991c0a7d5485/setup.cfg#L43.

    My solution was to change SQLAlchemy dependency to:

    SQLAlchemy = {version = ">=1.4,<1.4.23", extras = ["mypy"]}
    
  2. asifali22 commented on Aug 19, 2021

    @asifali22
    Author

    I faced the same issue. My problem was that I was using SQLAlchemy with version "^1.4".
    But yesterday SQLAlchemy released "1.4.23" with platform_machine constraint.

    Here's the link: https://github.com/sqlalchemy/sqlalchemy/blob/4331c1902ae341158b597769f4e4991c0a7d5485/setup.cfg#L43.

    My solution was to change SQLAlchemy dependency to:

    SQLAlchemy = {version = ">=1.4,<1.4.23", extras = ["mypy"]}
    

    Thanks this helped a lot.

    [tool.poetry.dependencies]
    python = "^3.8"
    python-dotenv = "^0.17.0"
    numpy = ">=1.19.2"
    pandas = "^1.2.4"
    Flask = "^1.1.2"
    Flask-SQLAlchemy = "^2.5.1"
    Flask-Migrate = "^2.7.0"
    python-jose = "^3.2.0"
    Flask-JWT = "^0.3.2"
    PyMySQL = "^1.0.2"
    psycopg2 = "^2.8.6"
    toolz = "^0.11.1"
    SQLAlchemy = {version = "*", extras = ["mypy"]}
    sortedcontainers = "^2.3.0"
    sqlalchemy-redshift = "^0.8.2"
    boto3 = "^1.17.57"
    joblib = "^1.0.1"
    xgboost = "^1.4.2"
    scikit-learn = "^0.24.2"
    redis = "^3.5.3"
    celery = {extras = ["redis"], version = "^5.1.0"}
    

    The above changes solved the issue for me. (Added SQLAlchemy)

  3. sdispater commented on Aug 19, 2021

    @sdispater
    Member

    Reopening since it should not crash like this when evaluating environment markers.

  4. pierresouchay commented on Aug 19, 2021

    @pierresouchay

    same issue here

  5. alonme commented on Aug 19, 2021

    @alonme
    Contributor

    I think adding the offending package name to the error is crucial

  6. josef-polak-heu commented on Aug 19, 2021

    @josef-polak-heu

    Hi, i hot fixed this by adding method allows to EmptyConstraint class:

    def allows(self, other):  # type: ("ConstraintTypes") -> bool
        return True
    

    to ./poetry/core/packages/constraints/empty_constraint.py

  7. trallnag commented on Aug 19, 2021

    @trallnag

    Pinning the version of sqlalchemy fixed it for me. Thanks @s3rius

    sqlalchemy = ">=1.4,<1.4.23"
    
  8. ftheo commented on Aug 19, 2021

    @ftheo

    Same issue as well. Agree there should be more information on the error/offending package as it required digging into each dependency to identify the package causing the issue

  9. monkey0head commented on Aug 19, 2021

    @monkey0head

    Hi, i hot fixed this by adding method allows to EmptyConstraint class:

    def allows(self, other):  # type: ("ConstraintTypes") -> bool
        return True
    

    to ./poetry/core/packages/constraints/empty_constraint.py

    Thanks @josef-polak-heu! Perfectly solved the problem for me.

  10. lgeo3 commented on Aug 19, 2021

    @lgeo3

    In the sqlalchemy repo, one developer is saying that it could be due to poetry-core not able to parse correctly constraint like:

    and platform_machine in "x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32"
    

    see comment here:
    sqlalchemy/sqlalchemy#6136 (comment)

    if we look at parse_single_constraint (in poetry-core/core/package/constraints/init.py it seems that such kind of constraint is not handled by poetry and thus end as an EmptyConstraint

    running an interactive debugging session we can see:

    ipdb> self
    <SingleMarker platform_machine in "x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32">
    ipdb> self._constraint
    <EmptyConstraint >
    ipdb> self._constraint_string
    'inx86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'
    

    So my question is for such kind of constraint string, the correct constraint type should be AnyConstraint isn't it ?

    On an other aspect Iam not sure that EmptyConstraint should provide a allows() that return True (maybee - see: it seems that someone already propose to add #4398 (comment)), but in my understanding, doing that will just hide the real problem here, that the constraint is not parsed correctly).

    I am maybee completly wrong, so don't hesitate to tell me.

  11. kupuguy commented on Aug 19, 2021

    @kupuguy

    I created an issue on sqlalchemy as I don't particularly care who is at fault, just want someone to fix it.
    sqlalchemy/sqlalchemy#6903

  12. 12 remaining items

  13. dwyatte commented on Aug 24, 2021

    @dwyatte

    Version 1.1.8 fixed the issue for me! Thanks @sdispater!

    Given #4429 and the fact that this error is in poetry-core, can one of the maintainers comment whether upgrading poetry-core>=1.0.4 is the better fix?

  14. github-actions commented on Mar 2, 2024

    @github-actions

    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.

  15. locked as resolved and limited conversation to collaborators on Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/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