Files
ClaudeandClaude Opus 5.5 55d0ef4938
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m9s
Independent Staging Quality Gate / validate-python (push) Successful in 7m26s
Independent Staging Quality Gate / publish (push) Successful in 2m46s
fix(report): the Narayana report extras are stored by one idempotent call, not only while chapters render (BUG-2107)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
2026-11-21 01:08:15 +08:00

44 lines
1.9 KiB
Python

"""BUG-2107: store the Narayana report extras in the packet, whoever needs them first.
`narayana_dasha_report_extras` (the start-sign candidates and both sub-period direction
readings, BUG-2088 / BUG-2105) used to be written only while the data chapters were rendered,
so a caller that built the reading facts without rendering first silently went without the
second reading. Both the renderer and the reading facts now call this.
"""
from __future__ import annotations
from typing import Any
EXTRAS_KEY = "narayana_dasha_report_extras"
def ensure_narayana_report_extras(packet: Any) -> dict:
"""Write `worksheets.timing_and_predictive_systems.narayana_dasha_report_extras` once.
Idempotent: a stored non-empty value is returned as it is. Nothing is written (and nothing is
raised) when the packet has no Narayana module or lacks the Lagna or planet longitudes. Only
that one key is written; the pinned `narayana_dasha` object and everything else are untouched.
Returns the stored extras, or {} when there are none.
"""
if not isinstance(packet, dict):
return {}
worksheets = packet.get("worksheets")
timing = worksheets.get("timing_and_predictive_systems") if isinstance(worksheets, dict) else None
stored = timing.get(EXTRAS_KEY) if isinstance(timing, dict) else None
if isinstance(stored, dict) and stored:
return stored
try:
from scripts.report_render.parity_chapters import narayana_extras_for_packet
except ModuleNotFoundError: # pragma: no cover - scripts/ on sys.path
from report_render.parity_chapters import narayana_extras_for_packet
extras = narayana_extras_for_packet(packet)
if not extras:
return {}
if not isinstance(worksheets, dict):
worksheets = packet.setdefault("worksheets", {})
if not isinstance(timing, dict):
timing = worksheets.setdefault("timing_and_predictive_systems", {})
timing[EXTRAS_KEY] = extras
return extras