Skip to content

To prevent dependabot-core from failing when the incorrect release tag is created for a release, adding a rescue statement#5615

Merged
honeyankit merged 18 commits intomainfrom
fix-pip-faiure-rate
Sep 7, 2022
Merged

To prevent dependabot-core from failing when the incorrect release tag is created for a release, adding a rescue statement#5615
honeyankit merged 18 commits intomainfrom
fix-pip-faiure-rate

Conversation

@honeyankit
Copy link
Copy Markdown
Contributor

@honeyankit honeyankit commented Sep 1, 2022

When the user creates a wrong release tag, the dependabot is not handling the exception and failing. The fix in this PR will catch such exception and will return nothing for such cases.

Error:

updater | ERROR <job_446384276> Error processing yarl (ArgumentError)
updater | ERROR <job_446384276> Malformed version number string 1.8.0..failed.release.attempt

Original issue: https://github.com/github/dependabot-updates/issues/2776

Nishnha and others added 3 commits September 1, 2022 15:41
…ful-errors

Revert "Add more helpful error messaging when a vulnerable dependency cannot be upgraded"
…g is created for a release, adding a rescue statement
@honeyankit honeyankit self-assigned this Sep 1, 2022
@honeyankit honeyankit requested a review from a team as a code owner September 1, 2022 22:54
Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hei @honeyankit! Nice to get rid of all these Python errors 🎉.

However I believe this rescue might not be the best solution.

While it correctly ignores this case, it may ignore many other things, including programming mistakes!

I think even if with decide to go with a silencing rescue, it should be more scoped to the exact place where this issue is happening.

How about trying to fix the actual culprit instead? I think you already identified the issue, this tag is getting incorrectly flagged as correct? by our version regexp. And that's why we later try to instantiate a Python::Version out of it.

I think the double dash is suspicious, I think the pattern may be unintentionally allowing that. Does this patch fix things?

diff --git a/python/lib/dependabot/python/version.rb b/python/lib/dependabot/python/version.rb
index 525be66d6..0290de9f0 100644
--- a/python/lib/dependabot/python/version.rb
+++ b/python/lib/dependabot/python/version.rb
@@ -16,7 +16,7 @@ module Dependabot
 
       # See https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
       VERSION_PATTERN = 'v?([1-9][0-9]*!)?[0-9]+[0-9a-zA-Z]*(?>\.[0-9a-zA-Z]+)*' \
-                        '(-[0-9A-Za-z-]+(\.[0-9a-zA-Z-]+)*)?' \
+                        '(-[0-9A-Za-z]+(\.[0-9a-zA-Z]+)*)?' \
                         '(\+[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)*)?'
       ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze
 

@mattt
Copy link
Copy Markdown
Contributor

mattt commented Sep 2, 2022

How about trying to fix the actual culprit instead? I think you already identified the issue, this tag is getting incorrectly flagged as correct? by our version regexp. And that's why we later try to instantiate a Python::Version out of it.

The linked PEP440 doc provides a regex pattern for matching version identifiers, but it's not obvious to me how that relates to the VERSION_PATTERN we use here. You might try copying that verbatim to see if that solves the problem at hand.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

I had the same thought, both regexp don't look the same to me. Anyways, I suggested a focused patch to what we currently have, because it seems "mostly" correct already (as per the different tests cases in the Version class unit specs).

I also checked that this version is not correct according to Python itself with

$ pyenv exec python
Python 3.10.5 (main, Aug 12 2022, 10:44:57) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from packaging.version import Version
>>> Version("v1.8.0--failed-release-attempt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/.pyenv/versions/3.10.5/lib/python3.10/site-packages/packaging/version.py", line 298, in __init__
    raise InvalidVersion("Invalid version: '{0}'".format(version))
packaging.version.InvalidVersion: Invalid version: 'v1.8.0--failed-release-attempt'

Also here's a little extra spec for this case!

diff --git a/python/spec/dependabot/python/version_spec.rb b/python/spec/dependabot/python/version_spec.rb
index 58ea79885..51f2cd33d 100644
--- a/python/spec/dependabot/python/version_spec.rb
+++ b/python/spec/dependabot/python/version_spec.rb
@@ -48,6 +48,11 @@ RSpec.describe Dependabot::Python::Version do
         let(:version_string) { "1.0.0+abc 123" }
         it { is_expected.to eq(false) }
       end
+
+      context "that includes two dashes" do
+        let(:version_string) { "v1.8.0--failed-release-attempt" }
+        it { is_expected.to eq(false) }
+      end
     end
   end

@mattt
Copy link
Copy Markdown
Contributor

mattt commented Sep 2, 2022

I had the same thought, both regexp don't look the same to me. Anyways, I suggested a focused patch to what we currently have, because it seems "mostly" correct already (as per the different tests cases in the Version class unit specs).

A focused change sounds good to me. And thanks for verifying the existing behavior in Python.

If we do change the regex, I'd really like to see a comment explaining that our regex has diverged from PEP440 (bonus points if we can articulate why).

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

For what it's worth the Python regexp never includes dashes in alphanumeric character classes, so this change at least brings us closer to the "upstream regexp".

@honeyankit
Copy link
Copy Markdown
Contributor Author

@deivid-rodriguez thanks for reviewing the PR and providing the suggestion. My initial thought was to modify the regex and remove the double-dash, since single dash is acceptable with for the python version. I tried version check with some other python module and it came out correct making me believe that version is correct, so changed my direction and use rescue to catch the exception.

@honeyankit honeyankit merged commit e73e93f into main Sep 7, 2022
@honeyankit honeyankit deleted the fix-pip-faiure-rate branch September 7, 2022 19:23
@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.

5 participants