Skip to content

Raise helpful errors for missing compiler contexts - #7517

Open
harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/7489-context-outside-compile
Open

harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/7489-context-outside-compile

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7489.

PageContext.get() and CompileContext.get() now raise descriptive RuntimeErrors when called outside page compilation or compilation, instead of exposing the raw ContextVar LookupError. Other BaseContext subclasses retain their existing LookupError behavior.

Adds regression tests and a reflex-base bugfix news fragment.

Validation: 47 focused tests passed; Ruff and Pyright passed.

View guided diff

@harsh21234i
harsh21234i requested a review from a team as a code owner October 8, 2026 10:24

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the clearer errors preserve the original exception type.

Summary

Adds helpful errors when PageContext.get() or CompileContext.get() is called outside compilation.

  • Keeps LookupError, preserving the original exception type.
  • Leaves other context classes’ missing-context behavior unchanged.
  • Adds message checks and a bugfix news fragment.
  • No new actionable issues found. Tests were inspected, not run.

Reviews (2) · Last reviewed commit: "Preserve LookupError for compiler contex..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.51%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 148 untouched benchmarks
⏩ 18 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_hydration_metadata[200] 1.9 ms 2.1 ms -9.46%
❌ test_hydration_metadata[20] 220.5 µs 233.4 µs -5.53%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing harsh21234i:fix/7489-context-outside-compile (a9a7cb9) with main (deea1c3)

Open in CodSpeed

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread packages/reflex-base/src/reflex_base/context/base.py Outdated

This branch has not been deployed

No deployments
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.

PageContext.get() / CompileContext.get() outside a compile raise a bare LookupError: <ContextVar name='PageContext' ...> instead of a message

2 participants