fix: harden state corp exchange imports
This commit is contained in:
@@ -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']}"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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="предмет закупки"),
|
||||
),
|
||||
]
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user