fix: double computation of contribution_totals (#36226)

This commit is contained in:
Beto Dealmeida
2025-11-25 14:35:55 -05:00
committed by GitHub
parent a4860075d2
commit aca18fff99
4 changed files with 180 additions and 16 deletions

View File

@@ -299,20 +299,24 @@ class QueryContextProcessor:
) -> dict[str, Any]:
"""Returns the query results with both metadata and data"""
self.ensure_totals_available()
# Skip ensure_totals_available when force_cached=True
# This prevents recalculating contribution_totals from cached results
if not force_cached:
self.ensure_totals_available()
# Update cache_values to reflect modifications made by ensure_totals_available()
# This ensures cache keys are generated from the actual query state
# We merge the original query dict with the updated query dict to preserve
# any fields that might not be in to_dict() but were in the original request
self._query_context.cache_values["queries"] = [
{**cached_query, **query.to_dict()}
for cached_query, query in zip(
self._query_context.cache_values["queries"],
self._query_context.queries,
strict=True,
)
]
# Update cache_values to reflect modifications made by
# ensure_totals_available()
# This ensures cache keys are generated from the actual query state
# We merge the original query dict with the updated query dict to preserve
# any fields that might not be in to_dict() but were in the original request
self._query_context.cache_values["queries"] = [
{**cached_query, **query.to_dict()}
for cached_query, query in zip(
self._query_context.cache_values["queries"],
self._query_context.queries,
strict=True,
)
]
query_results = [
get_query_results(