Fix: inverted ranges skip the overlap probe and hit the schema CHECK
The matrix test's end-before-start probe (expecting the schema's end>=start IntegrityError) hit the new overlap query first, since an inverted range lexically 'overlaps' the seeded row. The overlap check now runs only for well-ordered ranges; invalid ones fall through to the INSERT and keep the IntegrityError contract. Suite: 990 passed.
This commit is contained in:
@@ -205,12 +205,20 @@ class PresenceOverridesDao:
|
|||||||
)
|
)
|
||||||
if child is None:
|
if child is None:
|
||||||
raise ValueError(f"child {child_id} does not exist")
|
raise ValueError(f"child {child_id} does not exist")
|
||||||
conflicting = await self._database.fetch_one(
|
# Only a well-ordered range has overlap semantics:
|
||||||
f"SELECT {_OVERRIDE_COLUMNS} FROM presence_overrides "
|
# inverted ranges fall through to the INSERT and hit
|
||||||
"WHERE child_id = ? AND end_date >= ? "
|
# the schema's end>=start CHECK, preserving the
|
||||||
"AND start_date <= ? ORDER BY id LIMIT 1",
|
# IntegrityError contract the matrix tests rely on.
|
||||||
(child_id, start_date, end_date),
|
if end_date >= start_date:
|
||||||
)
|
conflicting = await self._database.fetch_one(
|
||||||
|
f"SELECT {_OVERRIDE_COLUMNS} "
|
||||||
|
"FROM presence_overrides "
|
||||||
|
"WHERE child_id = ? AND end_date >= ? "
|
||||||
|
"AND start_date <= ? ORDER BY id LIMIT 1",
|
||||||
|
(child_id, start_date, end_date),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
conflicting = None
|
||||||
if conflicting is not None:
|
if conflicting is not None:
|
||||||
conflict = _override_from_row(conflicting)
|
conflict = _override_from_row(conflicting)
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
Reference in New Issue
Block a user