2096 — Empty validated modules shown as "not validated" in Results¶
Problem¶
Validating a module that has no data entries did not register anywhere the
Results page reads validation from. In the overall results chart the module's
bar stayed greyed out with the "Validate {module} to see results" tooltip,
and its per-module section on the Results page kept the validation
placeholder card — even though the sidebar timeline correctly showed the
module as validated (it reads module_states, a different source).
Two independent read paths had the same bug:
-
validated_buckets(drives the chart)._build_report_stats(app/services/carbon_report_service.py) filtered the validated bucket list withand bucket_nodes.bucket.key in buckets. An empty module contributes no bucket to the merged stats, so its key was dropped fromvalidated_bucketsno matter its status. The frontend turnsvalidated_bucketsintovalidated_categories(frontend/src/utils/emissionStatsAdapter.tsfor the report-stats path), andModuleCarbonFootprintChart.vuegreys out any category not in that list and swaps its tooltip for the validate prompt. -
Results summary (drives the per-module section placeholders).
UnitTotalsService._validated_module_totalsskipped rows wherestatswas not a dict (Nonefor a never-computed module), so a validated empty module produced no key incurrent_emissions.compute_results_summaryemits onemodule_resultsrow per key, andResultsPage.vueshows the validation placeholder for any module without a row (getModuleResult(module)undefined).
Fix (commit ba51637e3)¶
_build_report_stats: removed thein bucketscondition —validated_bucketsnow lists every bucket key whose module type is validated, whether or not the bucket has data. Downstream consumers are safe with a validated-but-dataless key:derive_report_sectionsonly reads keys viabuckets.get(...),build_year_comparisonalready skipstotal_kg <= 0buckets, and the chart renders a normal (non-grey) zero bar via itsMAIN_RESULT_CATEGORIESplaceholder rows.UnitTotalsService._validated_module_totals: a validated module with non-dict stats now contributes0.0instead of being skipped, so the results summary emits a real row (0 t, 0 km equivalent) and the Results page shows zeros instead of the placeholder card.
No schema or endpoint shape changed; both fixes only change which keys the recompute writes / the summary read returns.
Rollout — stale persisted stats¶
validated_buckets lives in the persisted carbon_report.stats, rewritten
only by recompute_report_stats_many. Reports validated before this deploy
keep the old list until something re-triggers their aggregation, so the
chart symptom survives the deploy for existing data.
Backfill: POST /modules-sync/admin/recompute-stats (backoffice pipeline
permission) after deploy. It dispatches root aggregation jobs per
(module_type, year) scope with skip_module_status_update, so validation
statuses are preserved while carbon_report.stats is rebuilt under the new
code. The results-summary side needs no backfill — it derives from module
status + stats at read time.
Edge left open: a report whose modules are all empty refreshes no module in any scope, so its report rollup may not fire from the backfill. Re-validating any module of such a report rebuilds it.
Verification¶
- Validate a module with zero entries → overall results chart shows the category with a normal label, zero bar, standard tooltip (no "Validate X to see results"); the per-module Results section shows 0 t / 0 km instead of the placeholder card.
- Existing report from before the fix shows the old behavior until the admin recompute (or any data mutation on the report) runs, then matches.