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

helpful: fix handling of abbreviated ConfigArgparse arguments #9796

Merged
merged 7 commits into from
Oct 13, 2023
Merged

Conversation

wgreenberg
Copy link
Collaborator

ConfigArgparse allows for "abbreviated" arguments, i.e. just the prefix of an argument, but it doesn't set the argument sources in these cases. This commit checks for those cases and sets the sources appropriately.

Fixes #9793

Copy link
Member

@bmw bmw left a comment

Choose a reason for hiding this comment

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

I'm impressed! I personally expect anything related to any of our argument parsing to be a bit of a can of worms but you figured it out with a patch that makes sense to me very quickly. Nice work.

Two questions:

  1. Is just logging when we can't find the corresponding action what we want to do? Are there any alternative approaches you considered? I don't think I fully grok the implications of this.
  2. Do you think we should mention this in the changelog? I'm not sure if that was a purposeful omission or just something that wasn't thought about yet.

@wgreenberg
Copy link
Collaborator Author

  1. an action should always be found, so it's technically an error state if it isn't. my original thinking was that this error state isn't fatal, but should be logged in case it causes downstream issues, but perhaps it's actually best to error out when it happens? the result of an action not being found would be false negatives from set_by_user(ARG_WITH_NO_ACTION), which looks like it might lead to some confusing behavior
  2. d'oh i always forget a good changelog entry (despite it being in the PR template 🤦).

bmw
bmw previously approved these changes Oct 11, 2023
Copy link
Member

@bmw bmw left a comment

Choose a reason for hiding this comment

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

  1. Ah I see. I'm honestly on the fence. Normally I personally like the idea of failing fast, but it sounds like it's unlikely to matter much and it also looks like continuing without modifying result was our previous behavior for arguments set on the command line too.
  2. Haha no worries. I personally think in cases like this it is borderline anyway. My thinking basically is will someone in the future be trying to figure out in what release this was fixed? At this point, it seems unlikely.

If you want to change anything in response to (1) or (2) feel free and I'll prioritize giving it it another review but also feel free to merge as is.

@wgreenberg
Copy link
Collaborator Author

Maybe a compromise for 1 could be upgrading the log statement to .error(), so we'll at least get some heads up if it happens? Though it's difficult to think of a user-facing way of describing the issue clearly.

@bmw
Copy link
Member

bmw commented Oct 12, 2023

Yeah. I think you're right both that it's kind of a compromise and that it's hard to communicate. Mainly for the latter reason, I think I personally prefer our two original options:

  1. Blow up to ensure the error doesn't propagate and show up in unexpected ways.
  2. Debug logging like this PR currently does to help devs track down the problem if unexpected errors related to this ever happens.

Both seem unlikely though so I'm personally not too worried about it anymore.

@wgreenberg
Copy link
Collaborator Author

Sounds good, I think I'll opt for 1 since some of the false-positives from .set_by_user() look like they'd be both really annoying and subtle to notice. thanks!

@bmw
Copy link
Member

bmw commented Oct 12, 2023

Ooo it looks like the tests are triggering the case we (or at least I) thought shouldn't happen. Maybe annoying, but also maybe for the best in helping us understand all this and to do The Right Thing™ here.

One minor structural suggestion that you should feel free to push back on though: If we're going to error, maybe we should error inside _find_action_for_arg instead of returning None? I think it'd simplify things a bit and help keep things consistent.

@wgreenberg
Copy link
Collaborator Author

blowing things up always pays off! and sounds good re: moving the exception, i had two separate cases of it to make the error message slightly more descriptive, but it's probably not necessary

@wgreenberg wgreenberg force-pushed the fix-9793 branch 3 times, most recently from 722305d to 5d6c827 Compare October 12, 2023 22:37
@wgreenberg
Copy link
Collaborator Author

sorry for the mad commit churn on this, but i think it's in a good spot now for re-review. the CI caught some important edge cases which are now addressed!

@bmw
Copy link
Member

bmw commented Oct 13, 2023

No problem at all on the commit churn. I was going to wait for you to ping me or ask you before rereviewing.

PR LGTM except I think the changelog entry will get added to the 2.7.1 release when this is merged. Sorry for the inconvenience. You can fix this by merging in master and fixing up the changelog.

We/I should maybe tackle #8272, especially since I learned about towncrier.

ConfigArgparse allows for "abbreviated" arguments, i.e. just the prefix
of an argument, but it doesn't set the argument sources in these cases.
This commit checks for those cases and sets the sources appropriately.
These were silently being dropped before, possibly leading to instances
of `NamespaceConfig.set_by_user()` returning false negatives.
@wgreenberg
Copy link
Collaborator Author

changelog fixed! also towncrier looks great, i'll take a look at getting something going w/ it

@bmw
Copy link
Member

bmw commented Oct 13, 2023

also towncrier looks great, i'll take a look at getting something going w/ it

There's certainly no pressure from my end for you to do so, but #8272 was a newer version of #6462 so this issue has been an annoyance for Certbot devs for a long time that we've never prioritized fixing for whatever reason and it'd be awesome to see some progress on it.

@bmw bmw merged commit 11e17ef into master Oct 13, 2023
16 checks passed
@bmw bmw deleted the fix-9793 branch October 13, 2023 19:02
bmw pushed a commit that referenced this pull request Oct 18, 2023
* helpful: fix handling of abbreviated ConfigArgparse arguments

ConfigArgparse allows for "abbreviated" arguments, i.e. just the prefix
of an argument, but it doesn't set the argument sources in these cases.
This commit checks for those cases and sets the sources appropriately.

* failing to find an action raises an error instead of logging

* Update changelog

* Add handling for short arguments, fix equals sign handling

These were silently being dropped before, possibly leading to instances
of `NamespaceConfig.set_by_user()` returning false negatives.

(cherry picked from commit 11e17ef)
wgreenberg added a commit that referenced this pull request Oct 19, 2023
* helpful: fix handling of abbreviated ConfigArgparse arguments (#9796)

* helpful: fix handling of abbreviated ConfigArgparse arguments

ConfigArgparse allows for "abbreviated" arguments, i.e. just the prefix
of an argument, but it doesn't set the argument sources in these cases.
This commit checks for those cases and sets the sources appropriately.

* failing to find an action raises an error instead of logging

* Update changelog

* Add handling for short arguments, fix equals sign handling

These were silently being dropped before, possibly leading to instances
of `NamespaceConfig.set_by_user()` returning false negatives.

(cherry picked from commit 11e17ef)

* Fix finish_release.py (#9800)

* response is value

* rename vars

(cherry picked from commit a96fb4b)

* Merge pull request #9762 from certbot/docs/yaml-config

Add YAML files for Readthedocs requirements

(cherry picked from commit 44046c7)

* Update Lexicon requirements to stabilize certbot-dns-ovh behavior (#9802)

* Update minimum Lexicon version required for certbot-dns-ovh

* Add types

* FIx mypy

* Fix lint

* Fix BOTH lint and mypy

(cherry picked from commit 5cf5f36)

* simplify code (#9807)

(cherry picked from commit 6f7b5ab)

* Include linting fixes from 8a95c03

---------

Co-authored-by: Will Greenberg <willg@eff.org>
Co-authored-by: Alexis <alexis@eff.org>
Co-authored-by: Adrien Ferrand <adferrand@users.noreply.github.com>
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.

AttributeError: 'NoneType' object has no attribute 'dest'
2 participants