From 2dfd0fc856ddbc0943cdea52846ea9c2f9c0b81c Mon Sep 17 00:00:00 2001 From: adithiyan Date: Fri, 30 Oct 2026 11:51:48 +0530 Subject: [PATCH] fix(migration): sanitize attribute values and set clean human-readable repair variant names --- .../migration_engine/upsert_executor.py | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/services/migration_engine/upsert_executor.py b/app/services/migration_engine/upsert_executor.py index 2651025..2d6b214 100644 --- a/app/services/migration_engine/upsert_executor.py +++ b/app/services/migration_engine/upsert_executor.py @@ -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,