fix: an out-of-range cart timing is dropped, never refuses the quote

DTF-WEB-9: a cart left open for about 6 hours sent upload_ms 23556292,
above the 1 h limit, and POST /quotes answered 422: the customer could
not pay. The timings only feed Números, so a value out of range is now
dropped; an unknown field is still refused.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-12 15:34:41 -03:00
parent b8ee3fb35a
commit e80f376d91
2 changed files with 37 additions and 6 deletions

View File

@@ -253,17 +253,31 @@ class Item(StrictModel):
raise ValueError('Resolution warning must be acknowledged')
return self
TIMING_MAX = {'page_ms': 600000, 'upload_ms': 3600000, 'upload_bytes': 10**12,
'analysis_ms': 3600000, 'montage_ms': 3600000}
class ClientTimings(StrictModel):
"""What the browser measured on the way to a quote (item 0.12).
They are only numbers for Números; a cart may send none of them, and the
server never uses them to price or accept an order.
server never uses them to price or accept an order: a value out of range
(a cart left open for hours, DTF-WEB-9) is dropped, never refused.
"""
page_ms: int | None = Field(default=None, ge=0, le=600000)
upload_ms: int | None = Field(default=None, ge=0, le=3600000)
upload_bytes: int | None = Field(default=None, ge=0, le=10**12)
analysis_ms: int | None = Field(default=None, ge=0, le=3600000)
montage_ms: int | None = Field(default=None, ge=0, le=3600000)
page_ms: int | None = None
upload_ms: int | None = None
upload_bytes: int | None = None
analysis_ms: int | None = None
montage_ms: int | None = None
@model_validator(mode='before')
@classmethod
def drop_out_of_range(cls, data):
if not isinstance(data, dict):
return data
return {name: value for name, value in data.items()
if name not in TIMING_MAX or (isinstance(value, int) and not isinstance(value, bool)
and 0 <= value <= TIMING_MAX[name])}
class QuoteRequest(StrictModel):