Exclude cancelled reservations before ARR field review
This commit is contained in:
1 parent
36235e7d8d
commit
0c057a8e75
39 files changed
+1546
-56
No files matched your search
@@ -158,7 +158,7 @@ def _is_transient_database_error(error: Exception) -> bool:
|
||||
return isinstance(sqlstate, str) and sqlstate in TRANSIENT_SQLSTATES
|
||||
|
||||
|
||||
def _outcome_counts(payload: Mapping[str, Any]) -> Tuple[int, int, int, int, int]:
|
||||
def _outcome_counts(payload: Mapping[str, Any]) -> Tuple[int, int, int, int, int, int]:
|
||||
values = payload.get("outcome_counts")
|
||||
if not isinstance(values, Mapping):
|
||||
raise IngestionError(
|
||||
@@ -167,13 +167,14 @@ def _outcome_counts(payload: Mapping[str, Any]) -> Tuple[int, int, int, int, int
|
||||
)
|
||||
try:
|
||||
counts = tuple(
|
||||
int(values[name])
|
||||
int(values.get(name, 0) if name == "excluded_cancelled" else values[name])
|
||||
for name in (
|
||||
"retained",
|
||||
"excluded_rate_code",
|
||||
"duplicate",
|
||||
"validation_failed",
|
||||
"price_unmatched",
|
||||
"excluded_cancelled",
|
||||
)
|
||||
)
|
||||
except (KeyError, TypeError, ValueError):
|
||||
@@ -337,6 +338,32 @@ class PostgresIngestionRepository(IngestionRepository):
|
||||
if any(value not in definitions.get(key, "") for key, value in expected.items()):
|
||||
raise IngestionError("DATABASE_MIGRATION_MISSING", "direct data entry requires migration 019")
|
||||
self._run_transaction(check, "direct data schema could not be checked")
|
||||
self.assert_cancelled_scope_schema()
|
||||
|
||||
def assert_cancelled_scope_schema(self) -> None:
|
||||
"""Require the count and outcome constraints before either input is enabled."""
|
||||
def check(cursor):
|
||||
cursor.execute("""SELECT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'finance' AND table_name = 'daily_versions'
|
||||
AND column_name = 'excluded_cancelled_rows'
|
||||
AND data_type = 'integer' AND is_nullable = 'NO'
|
||||
), (
|
||||
SELECT pg_get_constraintdef(oid) FROM pg_constraint
|
||||
WHERE conrelid = 'finance.daily_versions'::regclass
|
||||
AND conname = 'daily_versions_counts_reconcile'
|
||||
), (
|
||||
SELECT pg_get_constraintdef(oid) FROM pg_constraint
|
||||
WHERE conrelid = 'finance.daily_records'::regclass
|
||||
AND conname = 'daily_records_outcome_check'
|
||||
)""")
|
||||
row = cursor.fetchone()
|
||||
if (not row or row[0] is not True
|
||||
or "excluded_cancelled_rows" not in str(row[1] or "")
|
||||
or "excluded_cancelled" not in str(row[2] or "")):
|
||||
raise IngestionError("DATABASE_MIGRATION_MISSING",
|
||||
"ARR processing requires migration 020")
|
||||
self._run_transaction(check, "ARR cancellation schema could not be checked")
|
||||
|
||||
def register_job(self, registration: JobRegistration) -> None:
|
||||
if (
|
||||
@@ -1809,13 +1836,14 @@ class PostgresIngestionRepository(IngestionRepository):
|
||||
duplicate_rows,
|
||||
validation_failed_rows,
|
||||
price_unmatched_rows,
|
||||
excluded_cancelled_rows,
|
||||
failure_code,
|
||||
failure_message,
|
||||
validated_at
|
||||
)
|
||||
VALUES (
|
||||
NULL, NULL, %s, %s, %s, %s, %s, 'rejected',
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
||||
%s, 'deterministic processing failed', now()
|
||||
)
|
||||
RETURNING id
|
||||
@@ -2047,11 +2075,12 @@ class PostgresIngestionRepository(IngestionRepository):
|
||||
duplicate_rows,
|
||||
validation_failed_rows,
|
||||
price_unmatched_rows,
|
||||
excluded_cancelled_rows,
|
||||
validated_at
|
||||
)
|
||||
VALUES (
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 'validated',
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, now()
|
||||
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, now()
|
||||
)
|
||||
RETURNING id
|
||||
""",
|
||||
|
||||
Reference in new issue
Block a user