Compare commits

..

No commits in common. "e6e4cd877b67478c7b5d4754c36f4e9e3836a201" and "5bec434e1f2ba2e8a6d23336e383d22a37995067" have entirely different histories.

2 changed files with 29 additions and 46 deletions

View File

@ -59,8 +59,7 @@ __all__ = [
"value_flags",
]
# строк на один INSERT: у строки формы 15 колонок, у значения 10, у `document_issue` 16; 16 × 1000 < 32767 параметров
# asyncpg
# строк на один INSERT: у строки формы 15 колонок, у значения 10; 15 × 1000 < 32767 параметров asyncpg
BATCH = 1000
@ -152,30 +151,34 @@ async def insert_statement(
async def add_issues(
session: AsyncSession, document_id: uuid.UUID, drafts: Sequence[IssueDraft], *, now: datetime.datetime
) -> None:
"""Записи `document_issue` документа из черновиков пакетами по `BATCH` (без commit)."""
issues = [
{
"id": uuid.uuid4(),
"document_id": document_id,
"kind": draft.kind,
"code": draft.code,
"severity": draft.severity,
"message": draft.message,
"line_ids": [str(line_id) for line_id in draft.line_ids] or None,
"column_id": draft.column_id,
"column_index": draft.column_index,
"codes": list(draft.codes) or None,
"field": draft.field,
"source": draft.source,
"relation": draft.relation,
"expected": draft.expected,
"actual": draft.actual,
"created_at": now,
}
for draft in drafts
]
for start in range(0, len(issues), BATCH):
await session.execute(insert(DocumentIssue).values(issues[start : start + BATCH]))
"""Записи `document_issue` документа из черновиков (без commit)."""
if not drafts:
return
await session.execute(
insert(DocumentIssue).values(
[
{
"id": uuid.uuid4(),
"document_id": document_id,
"kind": draft.kind,
"code": draft.code,
"severity": draft.severity,
"message": draft.message,
"line_ids": [str(line_id) for line_id in draft.line_ids] or None,
"column_id": draft.column_id,
"column_index": draft.column_index,
"codes": list(draft.codes) or None,
"field": draft.field,
"source": draft.source,
"relation": draft.relation,
"expected": draft.expected,
"actual": draft.actual,
"created_at": now,
}
for draft in drafts
]
)
)
async def delete_issues( # noqa: PLR0913 - фильтры записей независимы

View File

@ -527,23 +527,3 @@ async def test_osv_v2_sheet_needs_check_blocks_recognized(seeded: AsyncSession)
osv["status"] = "needs_check"
(document,) = await _map(seeded, entity, [osv])
assert document.status is DocumentStatus.NEEDS_CHECK
async def test_osv_v2_many_sheet_warnings_stored(seeded: AsyncSession) -> None:
"""AURORA-1711: предупреждений листа больше, чем помещается в один INSERT `document_issue` (16 параметров на
запись, лимит asyncpg 32 767 — ≈ 2 047 записей). Так было на «11.xlsx» (сч. 11, 2 128 строк «Кол. доп.»):
документ создаётся, все предупреждения сохранены."""
entity = await _entity(seeded)
osv = _osv_doc()
count = 2131
osv["warnings"] = [
{
"code": "OSV_ROWS",
"severity": "info",
"message": f"строка {row}: метка «Кол. доп.» в колонке «Показатели» не распознана",
}
for row in range(count)
]
(document,) = await _map(seeded, entity, [osv])
assert document.document_type is DocumentType.OSV
assert len(await _issues(seeded, document)) == count