Fix: initialize _pin in DebuggedApplication.__init__ to avoid Attribu… #3078
+19
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix AttributeError when pin_security=False (#3075)
Starting with werkzeug 3.1.4, initializing
DebuggedApplicationwithpin_security=Falseraises anAttributeErrorbecause thepinsetterattempts to delete
self._pinbefore it has been initialized.The issue occurs in
__init__whenpin_security=False: it callsself.pin = None, which triggers the setter that tries to executedel self._pin. Since_pinhasn't been created yet (it's lazilyinitialized by the getter), this raises an
AttributeError.The fix changes the setter to explicitly set
_pin = Noneinstead ofdeleting it. This prevents the error and ensures that when pin security
is disabled, the pin remains
Noneand doesn't get regenerated by thelazy getter. The type annotation for
_pinis also updated fromstrto
str | Noneto reflect that it can beNone.#3075
fixes #3075
Added test case
test_debugged_application_pin_security_false()thatverifies
DebuggedApplicationcan be initialized withpin_security=Falsewithout raising an error. The test would fail before the fix.
Updated type annotation for
_pinfromstrtostr | Noneto allowNonevalues.Added entry in CHANGES.rst under Version 3.2.0 (Unreleased) section.
No documentation changes needed as the behavior is now correct and
matches the documented API.