Repository navigation
Fix request lookup when frame locals mutate - #120
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation |
|---|---|---|
| Title check | The title clearly and concisely describes the main change: fixing request lookup when frame locals mutate. | |
| Linked Issues check | Issue #89 is closed and marked as historical context only. No active directly linked targets remain, so no linked-issue coding requirements apply. For context, the reviewed head changes `RequestUtil.g… |
|
| Out of Scope Changes check | The whole-PR diff from merge base 79d4d38 to head ecf03e8 changes three areas. (1) json_logging/util.py: the frame-local scan now iterates a snapshot tuple of values. This is the direct fix for #89.… |
|
| Description Check | Check skipped - CodeRabbit’s high-level summary is enabled. |
Full details: Linked Issues check
-
Explanation
Issue
#89is closed and marked as historical context only. No active directly linked targets remain, so no linked-issue coding requirements apply. For context, the reviewed head changesRequestUtil.get_request_from_call_stackinjson_logging/util.py. The loop now scanstuple(f_locals.values())instead of iterating the livef_localsdictionary by key. This removes theRuntimeError: dictionary changed size during iterationpath reported in#89. Therequestandreqchecks run before the loop and are unchanged. The loop still returns the first instance ofclass_type. Values under therequestandreqkeys that do not matchclass_typeproduce the same result in the loop as before, because the same value is tested again and fails again.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff from merge base 79d4d38 to head ecf03e8 changes three areas. (1)
json_logging/util.py: the frame-local scan now iterates a snapshot tuple of values. This is the direct fix for#89. (2)tests/test_fastapi.py: a regression test was added. The PR summary and raw summary state that it mutatesframe.f_localsfrom a trace hook and restores the previous tracer. This supports the fix and is in scope. I could not read the full test text because the repository output was truncated, so I did not verify its exact contents. (3)json_logging/util.py: the file now ends with a newline. This is a formatting-only change and is not a concern. No unrelated functional change was found in the inspected diff.
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
PR Summary by QodoSnapshot frame locals during request lookup to avoid mutation errors
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Extra locals snapshot allocations
|
There was a problem hiding this comment.
LlamaPReview — No blocking issues found
This PR safely fixes the RuntimeError by snapshotting frame locals before scanning, with a regression test that fails on the old code and no PR-caused correctness or security regressions found.
1 non-blocking finding retained — highest: Optional: per-frame tuple allocation in logging hot path.
Review details and evidence
| Priority | File | Finding | Evidence |
|---|---|---|---|
| P2 | json_logging/util.py |
Optional: per-frame tuple allocation in logging hot path | needs verification |
Finding details
P2 · Optional: per-frame tuple allocation in logging hot path
json_logging/util.py
The fix snapshots frame locals with tuple(f_locals.items()), adding a new O(n) allocation per scanned frame. The old loop already did O(n) work per frame, and typical frame-local counts are small; there is no evidence this is a material regression. Profiling of high-volume logging would determine if a follow-up optimization is warranted; this is not a merge blocker.
Owner action: Optionally profile high-volume logging to assess the tuple allocation cost; only optimize if a regression is measured.
Verification boundary: needs verification; scope: changed region.
Material unknowns
- Exact-head CI evidence for pytest/flake8/build is not independently present; only CodeRabbit status is available. Would confirm the change passes full CI rather than only statically analyzed; does not change the clear verdict.
- Check: Confirm CI run results on the final commit before merge for completeness.
LlamaPReview checks
- Read the complete PR-head file
json_logging/util.py. - Read the complete PR-head file
tests/test_fastapi.py.
LlamaPReview reviewed this pull request at its exact head commit. Inspect the source or share feedback.
|
@duclucky - Can you please rebase ? |
|
@duclucky - Would it be possible for you to rebase and address the qodo-code-review ... ? |
71fe7d6 to
ecf03e8
Compare
|
Thanks for addressing the requested changes, it now looks good. |
Summary
tuple(f_locals.values())to avoid allocating key/value pairs, while preserving the existingrequestandreqfast pathsframe.f_localsfrom a trace hook after iteration starts and restores the previous tracerFixes #89
Testing
python -m pytest --ignore tests/smoketests -q(98 passed)backend=fastapi python -m pytest tests/smoketests/test_run_smoketest.py -q(6 passed)python -m pytest --ignore tests/smoketests --ignore tests/test_gunicorn_flask.py -q(95 passed; Gunicorn is covered by the Linux run)python -m flake8 json_logging tests --count --select=E9,F63,F7,F82 --show-source --statistics(passed)python -m build --no-isolation(sdist and wheel built)uv pip check --python .venv/Scripts/python.exe(passed)RuntimeError: dictionary changed size during iteration; restoring it passesSummary by CodeRabbit
Bug Fixes
Tests