fix: two runtime bugs flagged by flake8 (NameError in auth, UnboundLocalError in timer)#604
Open
MacJediWizard wants to merge 1 commit intoDRYTRIX:mainfrom
Open
fix: two runtime bugs flagged by flake8 (NameError in auth, UnboundLocalError in timer)#604MacJediWizard wants to merge 1 commit intoDRYTRIX:mainfrom
MacJediWizard wants to merge 1 commit intoDRYTRIX:mainfrom
Conversation
These were caught by the project's own flake8 step but the failing
checks have been red on a number of recent runs, suggesting it's worth
fixing the underlying defects rather than ignoring the rule.
1. app/routes/auth.py β F821: undefined name 'datetime'
`current_user.two_factor_confirmed_at = datetime.utcnow()` (line ~620)
used `datetime` without importing it. Confirming 2FA raises
`NameError: name 'datetime' is not defined` at runtime.
Adds `from datetime import datetime` to the imports.
2. app/routes/timer.py β F823: local variable '_' referenced before assignment
`from flask_babel import gettext as _` is imported at module scope.
Four functions then unpack `can_start, _ = TimeTrackingService().can_start_timer(...)`
which makes `_` a function-local for the entire enclosing scope and
shadows the i18n alias. Three earlier `flash(_("..."))` calls in the
same functions (lines 171, 449, 2019) reference the local before it
exists and raise `UnboundLocalError` at runtime.
Fix: rename the throwaway slot from `_` to `_unused` in all four
`can_start_timer` unpackings. The translation alias resolves cleanly
in every flash() call again.
Total: +6 / -4 across two files.
Collaborator
|
@MacJediWizard Can you change the branch to develop? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two genuine runtime bugs in
v5.5.2. flake8 already flags them (F821, F823) β they're not stylistic.Bug 1 β
app/routes/auth.py:620βNameError: datetimecurrent_user.two_factor_confirmed_at = datetime.utcnow()referencesdatetimewithout importing it. The 2FA confirmation route raisesNameError: name 'datetime' is not definedwhenever a user finalises 2FA setup.flake8:
app/routes/auth.py:620:52: F821 undefined name 'datetime'Fix: add
from datetime import datetimeto the import block.Bug 2 β
app/routes/timer.pyβUnboundLocalErroron_Module level:
Four functions then unpack:
at lines 175, 339, 453, 2022. Python's scoping promotes
_to a function-local for the entire enclosing scope, shadowing the imported translation function. Threeflash(_("..."))calls in those functions sit BEFORE the local assignment (lines 171, 449, 2019) and now reference an uninitialised local βUnboundLocalErrorat runtime.flake8:
Fix: rename the throwaway slot from
_to_unusedin all fourcan_start_timerunpackings. The three previously-brokenflash(_("..."))calls now resolve the translation alias as intended.Reproduction
NameError.UnboundLocalError.Diff size
No behavioural change beyond bug elimination. Tested against
v5.5.2.