One bounded statement per chunk, stopping at the first failure. Returns the rows that were not written (the failed chunk and everything after it) so the caller retries only those; replaying the whole snapshot would count the landed chunks twice.
(
*, prisma_client: "PrismaClient", snapshot: RequestErrorSnapshot
)
| 201 | |
| 202 | |
| 203 | async def commit_request_errors_to_db( |
| 204 | *, prisma_client: "PrismaClient", snapshot: RequestErrorSnapshot |
| 205 | ) -> RequestErrorSnapshot: |
| 206 | """One bounded statement per chunk, stopping at the first failure. |
| 207 | |
| 208 | Returns the rows that were not written (the failed chunk and everything after it) so the |
| 209 | caller retries only those; replaying the whole snapshot would count the landed chunks twice. |
| 210 | """ |
| 211 | chunks: Final = tuple(_statement_chunks(snapshot)) |
| 212 | for index, chunk in enumerate(chunks): |
| 213 | try: |
| 214 | sql, params = build_request_errors_upsert(chunk) |
| 215 | async with db_span("commit_request_errors", "LiteLLM_DailyRequestErrors"): |
| 216 | await prisma_client.db.execute_raw(sql, *params) # pyright: ignore[reportAny] # untyped prisma client |
| 217 | except asyncio.CancelledError: |
| 218 | raise RequestErrorCommitCancelled(_rows_from(chunks, index)) from None |
| 219 | except Exception: # noqa: BLE001 -- keep the chunks already written, hand back the rest for retry |
| 220 | verbose_proxy_logger.warning( |
| 221 | "Request error tracking - statement %d of %d failed, %d rows go back for retry", |
| 222 | index + 1, |
| 223 | len(chunks), |
| 224 | sum(len(remaining) for remaining in chunks[index:]), |
| 225 | exc_info=True, |
| 226 | ) |
| 227 | return _rows_from(chunks, index) |
| 228 | verbose_proxy_logger.debug("Request error tracking - committed %d aggregated rows in one statement", len(chunk)) |
| 229 | return _NO_COUNTS |
| 230 | |
| 231 | |
| 232 | class RequestErrorRedisBuffer: |