fix(bigquery): address deferred review follow-ups

Cache persistence: persist bq_memory_limited flag in QueryCacheManager
so truncation warnings survive cache hits. The flag is now saved into
the cache value dict in set_query_result (reading from g and resetting
it there), and restored from cache in get(). get_df_payload now reads
cache.bq_memory_limited instead of g, removing the need for g entirely
in query_context_processor.py.

Frontend test: add two tests to chartActions.test.ts verifying that
addWarningToast is dispatched (with noDuplicate: true) when a query
response carries a warning field, and not dispatched when it doesn't.

Updated existing test_query_context_processor tests to set the flag on
mock_cache directly rather than patching g.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-04-07 13:43:11 -07:00
parent 1894b77b44
commit bbbd1490ef
4 changed files with 79 additions and 19 deletions

View File

@@ -21,7 +21,7 @@ import re
from typing import Any, cast, ClassVar, Sequence, TYPE_CHECKING
import pandas as pd
from flask import current_app, g
from flask import current_app
from flask_babel import gettext as _
from superset.common.chart_data import ChartDataResultFormat
@@ -191,12 +191,8 @@ class QueryContextProcessor:
cache.df.columns = [unescape_separator(col) for col in cache.df.columns.values]
warning: str | None = None
if getattr(g, "bq_memory_limited", False):
row_count = getattr(g, "bq_memory_limited_row_count", len(cache.df))
# Reset flags immediately so subsequent queries in the same request
# don't inherit this warning
g.bq_memory_limited = False
g.bq_memory_limited_row_count = 0
if cache.bq_memory_limited:
row_count = cache.bq_memory_limited_row_count
chart_id = (self._query_context.form_data or {}).get("slice_id", "")
prefix = f"Chart {chart_id}: " if chart_id else ""
warning = _(