fix(local_auth): define module logger to avoid NameError on admin bootstrap - #1
Open
G2P2 wants to merge 1 commit into
Open
fix(local_auth): define module logger to avoid NameError on admin bootstrap#1G2P2 wants to merge 1 commit into
G2P2 wants to merge 1 commit into
Conversation
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.
What is wrong
agentic_core/local_auth.pyuseslogger.warning(...)in_ensure_admin()(line 85 onmain), but the module never importsloggingand never defineslogger. Every other module inagentic_core/that logs does define one (e.g.cognito_auth.py:9,authing_auth.py:14,user_memory.py:13) — this one was missed.How it fails
_ensure_admin()is called first thing inlocal_login()and inlocal_list_users(). It hits thelogger.warningline whenever the admin user is not yet present in the config table andAGENTIC_AUTO_ADMIN_PASSWORDis unset — which is the default, sinceconfig/local_authdefault it to""and onlydeploy/china/deploy-cn.shrequires it. Note that_get_users()also swallows any DynamoDB error and returns{}, so a misconfigured or unreachable config table lands on the same path.The result is an uncaught
NameErrorinstead of the intended warning:POST /api/auth/local-login(api/main.py:3967) is an unauthenticated public path and does not catch this, so the endpoint returns HTTP 500 rather than the intended 401 with a clear error message.POST /api/auth/loginhas the same behaviour whenAGENTIC_AUTO_AUTH_PROVIDERislocalorauthing.The fix
Add
import loggingandlogger = logging.getLogger(__name__), matching the pattern used by the sibling modules. Three added lines, no behaviour change beyond the intended warning now being emitted.Verification
Ran
local_auth.pyin a clean Python 3.13 container withAGENTIC_AUTO_ADMIN_PASSWORDunset and no DynamoDB reachable.Before:
NameError: name logger is not defined(traceback above).After:
so the caller gets the error dict it expects and the endpoint can return 401.
python -m py_compile agentic_core/local_auth.pyalso passes.I did not exercise the full happy path (successful login writing to a real DynamoDB config table), as that needs AWS credentials and a provisioned table.