Skip to content

fix(fleet): handle non-object JSON command logging#73

Merged
Bre77 merged 3 commits into
mainfrom
fm/tfa-logresult-noneguard-d5
Jul 12, 2026
Merged

fix(fleet): handle non-object JSON command logging#73
Bre77 merged 3 commits into
mainfrom
fm/tfa-logresult-noneguard-d5

Conversation

@Bre77

@Bre77 Bre77 commented Jul 12, 2026

Copy link
Copy Markdown
Member

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

  • Guarded _log_request_result so successful requests with JSON null, lists, or scalar bodies no longer crash command-result logging.
  • Added regression coverage for non-dict JSON response bodies and fixed the test response helper so explicit None bodies are exercised correctly.
  • Documented REST endpoints that may return non-object JSON bodies across the public docs.

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=success

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=success

Pipeline

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.md
  • uv run pytest tests/test_command_logging.py
  • mkdir -p /tmp/no-mistakes-evidence/01KXAXMHRPTR061M4VTS6C4NRH && uv run python - <<'PY' > /tmp/no-mistakes-evidence/01KXAXMHRPTR061M4VTS6C4NRH/non_dict_json_request_transcript.txt ... PY
  • git status --short after cleanup
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

firstmate crewmate 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.
@Bre77 Bre77 merged commit c33d175 into main Jul 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant