Compare commits
No commits in common. "e6e4cd877b67478c7b5d4754c36f4e9e3836a201" and "5bec434e1f2ba2e8a6d23336e383d22a37995067" have entirely different histories.
e6e4cd877b
...
5bec434e1f
@ -59,8 +59,7 @@ __all__ = [
|
|||||||
"value_flags",
|
"value_flags",
|
||||||
]
|
]
|
||||||
|
|
||||||
# строк на один INSERT: у строки формы 15 колонок, у значения 10, у `document_issue` 16; 16 × 1000 < 32767 параметров
|
# строк на один INSERT: у строки формы 15 колонок, у значения 10; 15 × 1000 < 32767 параметров asyncpg
|
||||||
# asyncpg
|
|
||||||
BATCH = 1000
|
BATCH = 1000
|
||||||
|
|
||||||
|
|
||||||
@ -152,30 +151,34 @@ async def insert_statement(
|
|||||||
async def add_issues(
|
async def add_issues(
|
||||||
session: AsyncSession, document_id: uuid.UUID, drafts: Sequence[IssueDraft], *, now: datetime.datetime
|
session: AsyncSession, document_id: uuid.UUID, drafts: Sequence[IssueDraft], *, now: datetime.datetime
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Записи `document_issue` документа из черновиков пакетами по `BATCH` (без commit)."""
|
"""Записи `document_issue` документа из черновиков (без commit)."""
|
||||||
issues = [
|
if not drafts:
|
||||||
{
|
return
|
||||||
"id": uuid.uuid4(),
|
await session.execute(
|
||||||
"document_id": document_id,
|
insert(DocumentIssue).values(
|
||||||
"kind": draft.kind,
|
[
|
||||||
"code": draft.code,
|
{
|
||||||
"severity": draft.severity,
|
"id": uuid.uuid4(),
|
||||||
"message": draft.message,
|
"document_id": document_id,
|
||||||
"line_ids": [str(line_id) for line_id in draft.line_ids] or None,
|
"kind": draft.kind,
|
||||||
"column_id": draft.column_id,
|
"code": draft.code,
|
||||||
"column_index": draft.column_index,
|
"severity": draft.severity,
|
||||||
"codes": list(draft.codes) or None,
|
"message": draft.message,
|
||||||
"field": draft.field,
|
"line_ids": [str(line_id) for line_id in draft.line_ids] or None,
|
||||||
"source": draft.source,
|
"column_id": draft.column_id,
|
||||||
"relation": draft.relation,
|
"column_index": draft.column_index,
|
||||||
"expected": draft.expected,
|
"codes": list(draft.codes) or None,
|
||||||
"actual": draft.actual,
|
"field": draft.field,
|
||||||
"created_at": now,
|
"source": draft.source,
|
||||||
}
|
"relation": draft.relation,
|
||||||
for draft in drafts
|
"expected": draft.expected,
|
||||||
]
|
"actual": draft.actual,
|
||||||
for start in range(0, len(issues), BATCH):
|
"created_at": now,
|
||||||
await session.execute(insert(DocumentIssue).values(issues[start : start + BATCH]))
|
}
|
||||||
|
for draft in drafts
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def delete_issues( # noqa: PLR0913 - фильтры записей независимы
|
async def delete_issues( # noqa: PLR0913 - фильтры записей независимы
|
||||||
|
|||||||
@ -527,23 +527,3 @@ async def test_osv_v2_sheet_needs_check_blocks_recognized(seeded: AsyncSession)
|
|||||||
osv["status"] = "needs_check"
|
osv["status"] = "needs_check"
|
||||||
(document,) = await _map(seeded, entity, [osv])
|
(document,) = await _map(seeded, entity, [osv])
|
||||||
assert document.status is DocumentStatus.NEEDS_CHECK
|
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
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user