Fix AttributeError crash in Argument.dest on invalid option strings#14773
Fix AttributeError crash in Argument.dest on invalid option strings#14773EternalRights wants to merge 1 commit into
Conversation
|
You're right — #14429 fixed the crash path. repr no longer touches Ronny's original comment was two things: guard repr, and safe The test is synthetic because after #14429, repr is the only thing I'll update the description and rename the changelog (13817 is taken |
When a plugin registers an option with an invalid name (e.g. one that starts with a digit), argparse's Action.__init__ raises before the dest attribute is assigned. If Argument.dest then reads self._action.dest, it raises a secondary AttributeError instead of letting argparse report the real problem. Use getattr with a "<missing>" fallback so a missing dest attribute does not crash on access. Closes pytest-dev#13817
99e1c78 to
4d81b84
Compare
cb2ee5b to
ced9022
Compare
|
Let's see what Ronny says about this. IMHO having a |
|
|
||
| # Simulate the crash path: an option name that fails _set_opt_strings | ||
| # may result in an Action without a `dest` attribute. | ||
| class BrokenAction: |
There was a problem hiding this comment.
i need a p practical example of this failure - i never saw this in the wild
|
Took another look — no real crash path. argparse.Action.init sets self.dest first, and add_argument either returns a complete action or raises before Argument is constructed. After #14429 the only path through repr is safe too. I'll close this. |
Fix AttributeError crash in Argument.dest on invalid option strings
When pytest_addoption registers an option name that argparse rejects
(e.g. one starting with a digit), Action.init fails during
_set_opt_strings before self.dest is set. If Argument.dest then
reads self._action.dest, the secondary AttributeError hides the
original argparse error.
Fixed by using getattr(self._action, "dest", "") in the
dest property so a missing dest attribute does not cause a second
crash.
This complements #14429 by completing the fix RonnyPfannschmidt
originally requested on #13817.
Closes #13817