Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
asifali22 opened this issue Aug 19, 2021 · 19 comments · Fixed by python-poetry/poetry-core#188
Closed

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

asifali22 opened this issue Aug 19, 2021 · 19 comments · Fixed by python-poetry/poetry-core#188
Labels
kind/bug Something isn't working as expected

Comments

@asifali22
Copy link

asifali22 commented Aug 19, 2021

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 <[email protected]>"]

[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="[email protected]>"

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

@asifali22 asifali22 added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Aug 19, 2021
@s3rius
Copy link

s3rius commented Aug 19, 2021

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"]}

@asifali22
Copy link
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)

@sdispater
Copy link
Member

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

@sdispater sdispater reopened this Aug 19, 2021
@pierresouchay
Copy link

same issue here

@alonme
Copy link
Contributor

alonme commented Aug 19, 2021

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

@josef-polak-heu
Copy link

josef-polak-heu commented Aug 19, 2021

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

@trallnag
Copy link

trallnag commented Aug 19, 2021

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

sqlalchemy = ">=1.4,<1.4.23"

@ftheo
Copy link

ftheo commented Aug 19, 2021

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

@monkey0head
Copy link

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.

@lgeo3
Copy link

lgeo3 commented Aug 19, 2021

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.

@kupuguy
Copy link

kupuguy commented Aug 19, 2021

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

sdispater added a commit to python-poetry/poetry-core that referenced this issue Aug 19, 2021
sdispater added a commit to python-poetry/poetry-core that referenced this issue Aug 19, 2021
sdispater added a commit to python-poetry/poetry-core that referenced this issue Aug 19, 2021
Resolves python-poetry/poetry#4402

# Conflicts:
#	poetry/core/packages/constraints/base_constraint.py
#	poetry/core/packages/constraints/empty_constraint.py
@sdispater sdispater reopened this Aug 19, 2021
@sdispater
Copy link
Member

We have a fix ready on the poetry-core side.

We will make a new release of both poetry-core and poetry as soon as possible (either later today or tomorrow).

@sdispater
Copy link
Member

Release 1.1.8 – which hopefully fixes the issue – is out!

@Alesom
Copy link

Alesom commented Aug 19, 2021

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

@nacknime-official
Copy link

Yes, it works, thank you!

Release 1.1.8 – which hopefully fixes the issue – is out!

@chrisvdg
Copy link

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

Also fixed for me!

@deanja
Copy link

deanja commented Aug 22, 2021

A big "thank you" to everyone involved in describing and resolving this issue. Tomorrow I'm due to release Python code to production for the first time ever at our company. As a relative Python beginner this error had me despondent on Friday! Sunday afternoon, the issue is already fixed and the fix released. Just did a quick poetry self update and I'm back on track. I hope I can contribute to this project in future. Thank you all!

morne added a commit to morne/poetry-core that referenced this issue Aug 22, 2021
achimnol added a commit to achimnol/pycon-kr2021-samples that referenced this issue Aug 24, 2021
* poetry needs to be updated 1.18 or later due to
  python-poetry/poetry#4402
@dwyatte
Copy link

dwyatte commented Aug 24, 2021

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?

abompard added a commit to fedora-infra/datanommer that referenced this issue Aug 27, 2021
abompard added a commit to fedora-infra/datagrepper that referenced this issue Sep 6, 2021
alanorth added a commit to ilri/csv-metadata-quality that referenced this issue Sep 6, 2021
SQLAlchemy gets pulled in by csvkit's agate-sql dependency and there
is currently an issue with Poetry's parsing of the SQLAlchemy 1.4.23
constraints. Temporarily explicitly install a version of SQLAlchemy
that works (can remove later once Poetry fixes this). Anyways, I am
not using any SQLAlchemy features that I know of.

See: python-poetry/poetry#4402
@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented 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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet