fix(migration): sanitize attribute values and set clean human-readable repair variant names

This commit is contained in:
adithiyan 2026-10-30 11:51:48 +05:30
parent 0a46f77412
commit 2dfd0fc856

View file

@ -484,14 +484,19 @@ class UpsertExecutor:
if val:
all_attributes[key] = val
# Filter meaningful attributes for variant display & mapping (ignore placeholders & boolean flags)
PLACEHOLDER_VALUES = {"n/a", "na", "none", "null", "-", "true", "false", "undefined"}
clean_attributes = {
k: str(v).strip() for k, v in all_attributes.items()
if v is not None and str(v).strip() and str(v).strip().lower() not in PLACEHOLDER_VALUES
and k not in ("media_key", "parent_media_key", "is_active", "is_service_booking")
}
if all_attributes:
# Clear previous variant_attributes links for this variant
db_session.query(VariantAttribute).filter(VariantAttribute.variant_id == variant.variant_id).delete()
for attr_name, attr_val in all_attributes.items():
if not attr_val:
continue
for attr_name, attr_val in clean_attributes.items():
attr_code = attr_name.lower().strip().replace(" ", "_").replace("-", "_")
# Find or Create AttributeType in Master Attributes (attribute_types)
@ -636,13 +641,16 @@ class UpsertExecutor:
db_session.add(repair_service)
db_session.flush()
rv_name = variant.sku
if all_attributes:
attr_summary = " | ".join([str(v) for k, v in all_attributes.items() if k not in ("media_key", "parent_media_key")])
if attr_summary:
rv_name = attr_summary
if not rv_name:
rv_name = raw_name
# Prefer material/quality attribute, or meaningful attribute summary, or variant/product name
material_val = clean_attributes.get("material") or clean_attributes.get("quality")
if material_val:
rv_name = material_val
elif clean_attributes:
rv_name = " | ".join(clean_attributes.values())
elif raw_name and raw_name.strip():
rv_name = raw_name.strip()
else:
rv_name = variant.sku or "Standard Quality"
rv = db_session.query(RepairVariant).filter(
RepairVariant.repair_service_id == repair_service.repair_service_id,