Skip to content

fix: prevent query params leaking into typed session dict#857

Closed
temrjan wants to merge 1 commit intoAnswerDotAI:mainfrom
temrjan:fix/session-dict-nbdev
Closed

fix: prevent query params leaking into typed session dict#857
temrjan wants to merge 1 commit intoAnswerDotAI:mainfrom
temrjan:fix/session-dict-nbdev

Conversation

@temrjan
Copy link
Copy Markdown

@temrjan temrjan commented Apr 3, 2026

Summary

Fixes #845. Replaces #854 (closed — was editing .py directly instead of the nbdev notebook).

When a session parameter is type-hinted as dict, query parameters leak into the session because if anno is dict: return data in _find_p fires before the session name check. Since _find_ps merges query params into data, this returns contaminated data instead of the actual session.

Fix

Add a session name check before anno is dict in _find_p (in nbs/api/00_core.ipynb Cell 47):

if 'session'.startswith(arg.lower()) and anno is dict: return conn.scope.get('session', {})
if anno is dict: return data

One line, same pattern used throughout _find_p.

Changes

  • nbs/api/00_core.ipynb — source notebook fix
  • fasthtml/core.py — regenerated from notebook
  • tests/test_toaster.pytest_get_toaster_with_typehint now sets a toast before checking the typed endpoint

Test plan

  • test_get_toaster_with_typehint passes (was failing on main)
  • All 5 tests in test_toaster.py pass
  • No regressions — other dict-annotated params still get data

Move session name check before `anno is dict` in `_find_p` so that
`session: dict` returns the actual session scope instead of the
merged data dict (which includes query parameters).

Fixes AnswerDotAI#845

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@temrjan temrjan force-pushed the fix/session-dict-nbdev branch from 9e714c2 to c01c748 Compare April 3, 2026 04:20
@temrjan
Copy link
Copy Markdown
Author

temrjan commented Apr 3, 2026

Hey @jph00, thanks for the feedback on #854.

This time the fix is made in the nbdev notebook (nbs/api/00_core.ipynb), and core.py is regenerated from it. One line, same if-return pattern used throughout _find_p. No style changes, no extra whitespace.

@jph00
Copy link
Copy Markdown
Contributor

jph00 commented Apr 3, 2026

I don't think AI is going to be able to make effective PRs to this repo - sorry; will need careful human attention!

@jph00 jph00 closed this Apr 3, 2026
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.

[BUG] Typehinting session parameter pulls in query parameters

2 participants