fix(fleet): handle non-object JSON command logging#73
Merged
Conversation
added 3 commits
July 12, 2026 20:21
A JSON-legal response body that isn't a dict (null, list, or scalar - e.g. Teslemetry's list_authorized_clients returning null) crashed _request AFTER the HTTP request had already succeeded, since _log_request_result unconditionally called data.get() assuming a dict. It's DEBUG-level logging added purely for troubleshooting (#64) and must never break a successful request.
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.
Intent
Fix production regression: Commands._log_request_result (tesla_fleet_api/tesla/fleet.py, added in PR #64 / v1.6.4 as DEBUG-only troubleshooting logging with explicit no-behavior-change intent) unconditionally called data.get('response') assuming a dict body. Any JSON-legal non-dict response (real case: Teslemetry list_authorized_clients returning null) crashed AttributeError after the HTTP request already succeeded, surfacing as HTTP 500 in a captain's production Home Assistant Powerwall reconfigure flow (HACS integration energy reconfigure broke; router-beta avoided it only by pinning 1.6.3). Fix: guard _log_request_result with isinstance(data, dict) before calling .get(); for any non-dict body (null, list, scalar) log result=success and return early, preserving the function's 'must never break a successful request' intent from PR #64. Added regression tests in tests/test_command_logging.py for null/list/scalar JSON bodies, and fixed a latent None-vs-unset ambiguity in the test file's _fake_response helper (it previously treated an explicit json_body=None the same as 'not passed', silently defaulting to {}) so the null-body test can actually exercise a null body. Also added one line to AGENTS.md documenting the invariant. Deliberately scoped narrowly to this one bug per the task brief - did not touch the separate key-permissions hardening issue, which a different crew is handling in its own PR.
What Changed
_log_request_resultso successful requests with JSONnull, lists, or scalar bodies no longer crash command-result logging.Nonebodies are exercised correctly.Risk Assessment
✅ Low: The change is narrowly scoped to preventing debug logging from raising on JSON-legal non-dict response bodies, with focused regression coverage and no observed behavioral risk beyond preserving the successful response value.
Testing
Inspected the targeted diff, ran the command-logging regression suite successfully, captured an API-level transcript for null/list/scalar JSON responses, restored uv-generated egg-info changes, removed local test caches, and confirmed the worktree was clean afterward.
Evidence: Non-dict JSON request transcript
CASE null body from list_authorized_clients returned: None log: DEBUG:command=list_authorized_clients transport=fleet result=success CASE list body returned: [{'id': 1}] log: DEBUG:command=clients transport=fleet result=success CASE scalar body returned: True log: DEBUG:command=flag transport=fleet result=successPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
git diff 68f79c5b95d1ad5394fae1ec4247bca99d341af3..70d2479c2e3db3241fc85fe214e2c0dc1cc43bd4 -- tesla_fleet_api/tesla/fleet.py tests/test_command_logging.py AGENTS.mduv run pytest tests/test_command_logging.pymkdir -p /tmp/no-mistakes-evidence/01KXAXMHRPTR061M4VTS6C4NRH && uv run python - <<'PY' > /tmp/no-mistakes-evidence/01KXAXMHRPTR061M4VTS6C4NRH/non_dict_json_request_transcript.txt ... PYgit status --shortafter cleanup✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.