fix: close remaining ingestion review gaps

This commit is contained in:
2026-08-04 08:55:30 +02:00
parent 59ac108c90
commit f49b422095
6 changed files with 141 additions and 9 deletions
+7 -3
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
import json
from dataclasses import dataclass
from sqlalchemy import exists, or_, select
from sqlalchemy import exists, func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.data_import_run import DataImportRun
@@ -32,14 +32,18 @@ async def active_gaps(
matching_snapshot = exists().where(
FundamentalSnapshot.accession == SecFilingGap.accession
)
gap_date = func.coalesce(
SecFilingGap.index_date,
func.date(SecFilingGap.first_seen_at),
)
later_snapshot = exists().where(
FundamentalSnapshot.cik == SecFilingGap.cik,
FundamentalSnapshot.form.in_(_SEC_FORMS),
FundamentalSnapshot.filed_date > SecFilingGap.index_date,
FundamentalSnapshot.filed_date > gap_date,
)
stmt = select(SecFilingGap).where(
~matching_snapshot,
or_(SecFilingGap.index_date.is_(None), ~later_snapshot),
~later_snapshot,
)
if ciks is not None:
if not ciks: