fiscal_periods carries two FKs back to journal_entries (closing_entry_id, opening_balance_entry_id), so the bare fiscal_periods(...) embed in resolveUnderlagAnchoring is ambiguous on prod and every lock-state read failed on the first underlag-reconcile cron run: 34 locked-period items were treated as retryable and hit the period-lock trigger daily. The embed now names journal_entries_fiscal_period_id_fkey (same hint the MCP server uses) and the exact select string is pinned in the unit test, since mocks cannot see PostgREST ambiguity. Follow-up to #2012 (issue #1548).
This commit is contained in:
@@ -428,6 +428,12 @@ describe('resolveUnderlagAnchoring', () => {
|
||||
// Already anchored: the lock does not matter and it is not looked up.
|
||||
expect(map.get('i-d')?.status).toBe('anchored')
|
||||
expect(findCalls('journal_entries', 'in')).toEqual([['id', [JE1, JE2, 'je-open']]])
|
||||
// The bare `fiscal_periods(...)` embed is ambiguous on prod (fiscal_periods
|
||||
// has closing_entry_id and opening_balance_entry_id back to journal_entries)
|
||||
// and made every lock-state read fail on the first cron run (2026-08-29).
|
||||
expect(findCalls('journal_entries', 'select')).toEqual([
|
||||
['id, fiscal_period:fiscal_periods!journal_entries_fiscal_period_id_fkey(is_closed, locked_at)'],
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps an unlinked item unlinked (retryable) when the lock-state read fails', async () => {
|
||||
|
||||
@@ -232,7 +232,10 @@ async function resolveLockedJournalEntryIds(
|
||||
if (entryIds.length === 0) return locked
|
||||
const { data, error } = await supabase
|
||||
.from('journal_entries')
|
||||
.select('id, fiscal_period:fiscal_periods(is_closed, locked_at)')
|
||||
// fiscal_periods also points back at journal_entries (closing_entry_id,
|
||||
// opening_balance_entry_id), so PostgREST refuses the bare embed as
|
||||
// ambiguous; name the FK explicitly.
|
||||
.select('id, fiscal_period:fiscal_periods!journal_entries_fiscal_period_id_fkey(is_closed, locked_at)')
|
||||
.in('id', entryIds)
|
||||
.eq('company_id', companyId)
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user