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

Fix crash when updating Python libraries with multiple manifest types #5932

Merged
merged 3 commits into from Oct 20, 2022

Conversation

deivid-rodriguez
Copy link
Contributor

I discovered this issue while wrapping up #5661. However, the issue is already there so I think it makes sense to extract it to its own PR.

If a library has both a pyproject.toml file and a standard requirements.txt file, we'd end up using the :widen strategy for the dependencies in the requirements.txt file if the project is a library, and eventually crashing with an error like the following:

/home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `block in preferred_version_resolvable_with_unlock?': undefined method `[]' for nil:NilClass (NoMethodError)
    
       updated_requirements.none? { |r| r[:requirement] == :unfixable }
                                              ^^^^^^^^^^^^^^
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `none?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `preferred_version_resolvable_with_unlock?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:249:in `numeric_version_can_update?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:199:in `version_can_update?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:44:in `can_update?'
        from bin/dry-run.rb:709:in `block in <main>'
        from bin/dry-run.rb:661:in `each'
        from bin/dry-run.rb:661:in `<main>'

I think the crash happens because the requirements.txt file updater does not supoort the :widen strategy. So my fix is to fallback to increase in this case, since requirements.txt files usually include pinned dependencies so widening probably doesn't make much sense there.

@deivid-rodriguez deivid-rodriguez requested a review from a team as a code owner October 20, 2022 00:25
@deivid-rodriguez deivid-rodriguez marked this pull request as draft October 20, 2022 09:25
@deivid-rodriguez
Copy link
Contributor Author

Setting as draft because I'm not sure this is desired behavior. Nobody has complained about this so maybe best to not create the PR and just skip the crash.

@deivid-rodriguez
Copy link
Contributor Author

I reviewed the repository where I observed this, and repo maintainer was happily merging dependabot PRs before this bug appeared. So I say let's go with this approach and restore those PRs.

@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review October 20, 2022 12:01
If a library has both a pyproject.toml file and a standard
requirements.txt file, we'd end up using the `:widen` strategy for the
dependencies in the `requirements.txt` file and eventually crashing with
an error like the following:

```
/home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `block in preferred_version_resolvable_with_unlock?': undefined method `[]' for nil:NilClass (NoMethodError)

        updated_requirements.none? { |r| r[:requirement] == :unfixable }
                                          ^^^^^^^^^^^^^^
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `none?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:266:in `preferred_version_resolvable_with_unlock?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:249:in `numeric_version_can_update?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:199:in `version_can_update?'
        from /home/dependabot/dependabot-core/common/lib/dependabot/update_checkers/base.rb:44:in `can_update?'
        from bin/dry-run.rb:709:in `block in <main>'
        from bin/dry-run.rb:661:in `each'
        from bin/dry-run.rb:661:in `<main>'
```

I think the crash happens because the requirements.txt file updater does
not supoort the `:widen` strategy. So my fix is to fallback to
`increase` in this case, since requirements.txt files usually include
pinned dependencies so widening probably doesn't make much sense there.
@deivid-rodriguez deivid-rodriguez merged commit 7d9123b into main Oct 20, 2022
@deivid-rodriguez deivid-rodriguez deleted the deivid-rodriguez/python-crash branch October 20, 2022 21:10
@pavera pavera mentioned this pull request Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants