Menu ▾ ▴

#196 CTA test flags only entity-periods that translated at a non-closing rate (#195)

closed
nobody
None
2026-09-14
2026-09-14
Anonymous
No

Originally created by: grynn-in

Fixes [#195]: assert_cta_not_zero_when_rates_differ failed entities whose every row translated at the closing rate.

What was wrong

The test flagged every cross-currency entity-period where closing_rate and average_rate differ and gold_fx_revaluation.cta_amount is 0. But CTA is the residual of translating at more than one rate. An entity with balance-sheet rows only (no P&L rows) and no Historical Equity Rate translates every row at the closing rate, so its CTA is 0 by construction. Since [#176] a missing historical equity rate is a warning with the closing-rate fallback, so this is a normal case. On the stack one such entity made a full build fail on 4 entity-periods and skip the 7 consolidation models downstream.

The fix

The test's rate_check CTE also requires countIf(translation_rate != closing_rate) > 0: at least one row of the entity-period used a rate other than its closing rate. A P&L row at average or an equity row at a historical rate with CTA 0 is still flagged. The header comment now explains what CTA is and when it must be non-zero.

Evidence

  • Test first, with committed fixtures in the new dbt_project/test_fixtures/ folder (dbt ignores it; a README explains the ZZ rule and the scratch-schema gate):
  • assert_cta_not_zero_when_rates_differ.sql (a balance-sheet-only entity with CTA 0, plus an entity with a P&L row and a real CTA): Got 1 result on main (df6fa66) → PASS with the fix (77cd498).
  • assert_cta_not_zero_when_rates_differ.must_flag.sql (a P&L row at average, CTA 0): Got 1 result before and after.
  • Both runs were in throwaway zzg_gold schemas inside the stack's ClickHouse, with the live tables' DDL; live tables untouched.
  • Live data, read-only: the fixed test returns 0 rows on konsolidat.local (main's version returns 4).

🤖 Generated with Claude Code

https://claude.ai/code/session_013WewQKFQgG7o2M3mUDPRR5

Related

Tickets: #176
Tickets: #195
Tickets: #197
Tickets: #202

Discussion

  • Anonymous

    Anonymous - 2026-09-14

    Originally posted by: grynn-in

    Review round 1: three findings.

    1. Stale user-guide line (docs/user-guide/consolidation-guide.md): fixed in edf82d4.
    2. "Header cites a nonexistent test": rejected. dbt_project/tests/assert_translation_rate_resolved.sql exists on main (and is the subject of [#197]). The NULL remark stays: ClickHouse's countIf ignores a NULL comparison, and the table's column is Nullable even though the model's throwIf stops a build before a NULL lands.
    3. Drop abs(max(closing_rate) - max(average_rate)) > 0.0001: accepted. With equal closing and average rates an equity row at a historical rate still leaves a residual, and the old condition silenced a reported CTA of 0 there. Test first: a ZZHE case (closing = average = 1.2, equity row at 1.0, CTA 0) added to the must-flag fixture gives Got 1 result at 6af346d (not flagged); with the fix (edf82d4) the fixture gives Got 2 results and the pass fixture still passes. Live, read-only: the fixed test returns 0 rows on the stack.
     

    Related

    Tickets: #197

  • Anonymous

    Anonymous - 2026-09-14

    Ticket changed by: grynn-in

    • status: open --> closed
     

Log in to post a comment.