fix(ai): корректные счётчики created/updated/unchanged в отчёте импорта

_import_one возвращал неверные счётчики: новый документ давал created=1 и
updated=1 (лишний updated), а существующий без изменений не учитывался в
unchanged. Из-за этого падали test_creates_new_documents_and_publishes и
test_reimport_same_content_is_unchanged.

Разделены три состояния: новый → created=1; существующий без изменений →
unchanged=1; существующий с изменённым контентом → updated=1. Создание версии
вынесено в _publish_version.

Проверено: 43 теста hub_platform.ai зелёные.
This commit is contained in:
Andrey committed 2026-07-10 02:36:41 +03:00
1 parent a59300de70
commit ff090100cd
1 file changed
+23 -2
@@ -152,9 +152,30 @@ def _import_one(
code=doc.code,
defaults=defaults,
)
if created:
# Новый документ: первая версия будет создана ниже.
return _publish_version(
document=document,
version_model=version_model,
doc=doc,
author=author,
after_publish=after_publish,
report=ImportReport(created=1),
)
latest = _latest_published(version_model, document)
if latest and latest.content == doc.content:
return ImportReport(created=int(created))
return ImportReport(unchanged=1)
return _publish_version(
document=document,
version_model=version_model,
doc=doc,
author=author,
after_publish=after_publish,
report=ImportReport(updated=1),
)
def _publish_version(*, document, version_model, doc, author, after_publish, report):
version = version_model.objects.create(
document=document,
version=_next_version(version_model, document),
@@ -164,4 +185,4 @@ def _import_one(
document_service.publish_version(version=version)
if after_publish is not None:
after_publish(version)
return ImportReport(created=int(created), updated=1)
return report