Fix 500 when a toggle or refresh clears the chart cache mid-request - #209
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The lazy chart route read the shared df_cache, stats_cache, and chart_cache dicts with direct indexing and a check-then-use pattern. FastHTML runs the sync handlers in a thread pool, so a toggle, refresh, or search that clears a cache between the check and the read makes the route raise KeyError and return a 500. Read each cache once into a local and rebuild on a miss, so the request holds its own references that a concurrent clear cannot remove. calculate_metric_stats now accepts an explicit dataframe and returns the stats. Add a regression test that clears every cache during chart creation and asserts the route still renders. Generated-By: PostHog Desktop Task-Id: 6e8d2f02-9a52-45fd-a954-48b673129c29
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
📊 Test Coverage ReportCoverage: 56% (yellow) ✅ Coverage maintained or improved!
|
This branch has not been deployed
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.
Problem
/batch/{batch_name}/chart/{chart_index}indexed the shareddf_cache,stats_cache, andchart_cachedicts directly and used a check-then-use onchart_cache.chart_cache.clear()), a refresh (deletes one batch), or a search (clear_batch_cache) landing mid-request removes the key, so the route raisesKeyErrorand returns a 500 instead of a chart.Changes
chart_cachecheck-then-use withsetdefaultplus a localfig; the render now uses that local instead of indexing the dict a second time.calculate_metric_statsaccepts an explicit dataframe and returns the stats, so the caller never re-reads a dict that may have been cleared.KeyErroron the old code.Test plan
pytest tests/test_dashboard.py— 9 passedruff checkandruff formatclean on the changed filesKeyErroragainst the pre-fix render path and passes afterCreated with PostHog Desktop from this inbox report.