pyupio / safety

Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected.
https://safetycli.com/product/safety-cli
MIT License
1.66k stars 141 forks source link

dependency on old pydantic causes conflicts with other packages #495

Open washeck opened 5 months ago

washeck commented 5 months ago

Description

safety 3.0.0 depends on pydantic <2, while other packages require v2 (e.g. django-qr-code depends on pydantic >2.5)

What I Did

$ poetry add safety
Using version ^3.0.0 for safety
...
Because no versions of safety match >3.0.0,<4.0.0
 and safety (3.0.0) depends on pydantic (>=1.10.12,<2.0), safety (>=3.0.0,<4.0.0) requires pydantic (>=1.10.12,<2.0).
And because django-qr-code (4.0.1) depends on pydantic (>=2.5), safety (>=3.0.0,<4.0.0) is incompatible with django-qr-code (4.0.1).
yeisonvargasf commented 5 months ago

@washeck, that's correct; we expect to migrate to pydantic > 2.5 inside safety-schemas soon.

washeck commented 5 months ago

Well, until this is fixed, we cannot use safety because there is no way for the new and old pydantic to cooexist in one project and we cannot drop library used in our production system just because of development support tool.

I understand this is more a problem caused by pydantic authors, but IMHO you should consider not requiring the users of safety to install pydantic. See e.g. jedi-language-server changelog:

Removed pydantic dependency; it made distributing jedi-language-server harder than it needed to be.

frwickst commented 5 months ago

We have run into this issue as well. Just for the Safety folks here, there are ways to support both Pydantic 2 and 1 in the same version. As Pydantic 2 actually includes the entire v1 lib.

This means that you can upgrade to version 2 with minimal changes (mainly import changes) and then migrate to the actual v2 features later down the line.

Documentation: https://docs.pydantic.dev/latest/migration/#continue-using-pydantic-v1-features

PS. If you want an example of a big project that is facing the same type of issues, you can have a look at Home Assistant and more specifically this issue https://github.com/home-assistant/core/issues/99218

akjmicro commented 5 months ago

Yeah, safety folks, this is a big one. Working here at my company on an airflow container ecosystem, this is only dependency causing compatibility issues ATM.

yeisonvargasf commented 5 months ago

Hi folks, thanks for the report here. We should get this resolved next week.

@frwickst, thanks for the hints.

@washeck, in the short term, we aren't considering dropping Pydantic, this dependency conflict will be solved soon.

matthiaskoenig commented 5 months ago

Thanks. Same issue here.

yeisonvargasf commented 4 months ago

Hi, thanks for the patience here, we will soon release an update that supports 1.x and 2.x

yeisonvargasf commented 4 months ago

A safety_schemas version 0.0.2 is available, which includes compatibility for Pydantic 1.x and 2.x.

Can you try to install Safety, Pydantic 2.x, and safety_schemas 0.0.2 with pip? Safety 3.0.1 still has the specifier for pydantic<2.0; we will remove it once we get some feedback from users.

dotlambda commented 4 months ago

@yeisonvargasf Works on NixOS. Thanks a lot!

Pacheco95 commented 4 months ago

@yeisonvargasf didn't work for python:3.12 container:

fastapi~=0.109.2
pydantic-settings~=2.1.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pydantic-settings 2.1.0 requires pydantic>=2.3.0, but you have pydantic 1.10.14 which is incompatible.
sobolevbel commented 4 months ago
pip-compile --upgrade requirements/tests.in

Could not find a version that matches pydantic<2.0,<3.0.0,>=1.10.12,>=2.5.3 (from safety==3.0.1->-r requirements/tests.in (line 8))

...

There are incompatible versions in the resolved dependencies:
  pydantic<3.0.0,>=2.5.3 (from maison==1.4.3->autoimport==1.4.0->-r requirements/tests.in (line 33))
  pydantic<2.0,>=1.10.12 (from safety==3.0.1->-r requirements/tests.in (line 8))
  pydantic (from safety-schemas==0.0.2->safety==3.0.1->-r requirements/tests.in (line 8))

Kindly ask you to take into consideration removing pydantic from your dependencies if it isn't crucial.

FluxZA commented 4 months ago

@yeisonvargasf Working for us on Py 3.11

sobolevbel commented 3 months ago

Sorry for asking, but we're waiting for the fix. Do you know when will it be available for everyone?

yeisonvargasf commented 3 months ago

The upper range limit was removed on Safety 3.1.0 version.

RafaelWO commented 1 month ago

Great! I believe this can be closed then, right? 🙂