To prevent dependabot-core from failing when the incorrect release tag is created for a release, adding a rescue statement#5615
Conversation
…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
deivid-rodriguez
left a comment
There was a problem hiding this comment.
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
The linked PEP440 doc provides a regex pattern for matching version identifiers, but it's not obvious to me how that relates to the |
|
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 I also checked that this version is not correct according to Python itself with 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 |
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). |
|
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". |
|
@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. |
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:
Original issue: https://github.com/github/dependabot-updates/issues/2776