fix: harden state corp exchange imports
Some checks failed
CI/CD Pipeline / Run Tests (push) Successful in 2m47s
CI/CD Pipeline / Code Quality Checks (push) Failing after 2m47s
CI/CD Pipeline / Build and Push Dev Images (push) Has been skipped
CI/CD Pipeline / Deploy Dev via Compose (push) Has been skipped

This commit is contained in:
2026-07-22 14:23:05 +02:00
parent 9eb41f6fd4
commit 0dbbe1afa9
7 changed files with 152 additions and 1 deletions

View File

@@ -41,6 +41,15 @@ def _check_db(timeout_seconds: int) -> tuple[bool, str]:
with conn.cursor() as cursor:
cursor.execute("SELECT 1")
cursor.fetchone()
cursor.execute("SHOW server_encoding")
encoding = str(cursor.fetchone()[0]).upper()
if encoding != "UTF8":
target = f"{params['host']}:{params['port']}/{params['dbname']}"
return (
False,
f"{target} (database encoding {encoding} is unsupported; "
"UTF8 is required)",
)
return True, "OK"
except Exception as exc: # noqa: BLE001
target = f"{params['host']}:{params['port']}/{params['dbname']}"

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
import base64
import hashlib
import json
import logging
import struct
import uuid
import zlib
@@ -41,6 +42,8 @@ from django.db import transaction
from django.db.models import Q
from django.utils import timezone
logger = logging.getLogger(__name__)
class ExchangeImportError(ValueError):
"""Exchange package validation or import error."""
@@ -282,6 +285,13 @@ class ExchangePackageImportService:
)
raise
except Exception as exc: # noqa: BLE001
logger.exception(
"Unexpected exchange package import failure "
"(package_id=%s, package_hash=%s, delivery_channel=%s)",
package_id,
decoded.package_hash,
delivery_channel,
)
error_message = "Не удалось импортировать пакет обмена"
cls._create_failed_record(
decoded=decoded,

View File

@@ -0,0 +1,15 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("external_data", "0004_auto_20260527_1928"),
]
operations = [
migrations.AlterField(
model_name="publicprocurement",
name="purchase_name",
field=models.TextField(verbose_name="предмет закупки"),
),
]

View File

@@ -134,7 +134,7 @@ class PublicProcurement(UUIDPrimaryKeyMixin, TimestampMixin, models.Model):
execution_end_date = models.DateField(
_("дата окончания исполнения"), null=True, blank=True
)
purchase_name = models.CharField(_("предмет закупки"), max_length=500)
purchase_name = models.TextField(_("предмет закупки"))
class Meta:
ordering = ["-contract_date", "purchase_number"]