The `--fix` flag doesn't work for dependencies of top-level requirements
See original GitHub issueI’m still working on a repro for this but just from reading the code, I’m pretty sure that this isn’t correct. When running --fix
on the current environment it works like this:
- Figure out what version to upgrade the broken dependency to.
- Upgrade it and ignore any other package that uses that dependency. If we have packages that don’t work properly with the upgraded dependency, too bad.
I think this is reasonable for an automated fix. However, for requirements files our approach doesn’t work well. We’re currently doing:
- Figure out what version to upgrade the broken dependency to.
- Scan the requirements file and look for a matching dependency and update it.
However, transitive dependencies won’t necessarily appear in the requirements file unless the requirements have pinned hashes. So in this case, the fix won’t be applied to the requirements file. I think we have a few options here:
- Rewrite the
--fix
logic to work differently for requirements files. We’ll need something that identifies which top-level requirement a dependency belongs to and then upgrade the top-level requirement, check whether it fixed the vulnerability, rinse, repeat. - Make
--fix
write a new line to the requirements file explicitly listing the fixed dependency if it isn’t already there. - Only allow
--fix
in combination with--require-hashes
or--no-deps
since we know we’ll have the full set of dependencies in the requirements file.
At the moment, I’m trying to find a package that has a vulnerability in its dependency so I can actually test this out.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Allow pip install flags to be recognized in environment files
As a work-around for this issue, you can do the following: Put your dependencies in a requirements.txt file; Change your environment.yml file so ......
Read more >Getting " error: Potentially incompatible change required to ...
Constraints on package "joshowens:accounts-entry": To allow potentially incompatible changes to top-level dependencies, you must pass --allow- ...
Read more >Stanza Reference - Dune documentation - Read the Docs
Note that the use of a using stanza (see using) doesn't automatically add the associated library or tool as a dependency. They have...
Read more >pipdeptree
Command line utility to show dependency tree of packages. ... To fix this, pipdeptree must be run with a -f or --freeze flag....
Read more >User Guide - pip documentation v22.3.1
Requirements files are used to override a dependency with a local patch that lives ... For instance, say that the “helloworld” package doesn't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sort of — I’m imagining a situation where the user specifies version N of a package, which has a sub dependency with version Q. Q has a vulnerability, so we upgrade it to Q’. The user then later manually (or automatically) upgrades N to N’, which happens to remove Q from its dependency set. With that, the user would be left with an “orphaned” dependency on Q’ in their requirements, since it’s no longer a subdependency.
Sent from mobile. Please excuse my brevity.
Forgot to mention: if we end up in a state like https://github.com/trailofbits/pip-audit/issues/291#issuecomment-1153246005 where
Q'
is now an orphaned dependency, it might make sense to offer the user some advice and suggest that they remove it (or even do so automatically).We could possibly do that by tracking our own comments (added during
--fix
) and making sure that any associated deps appear nowhere else in the tree, implying that they’ve been orphaned.