fix: Update _normalize_metadata_casefold and _first_nonempty to handle various data types

This commit is contained in:
JB
2025-11-30 12:36:58 -08:00
parent 07c78255e8
commit 76b3aae341
+11 -3
View File
@@ -228,8 +228,8 @@ class Job:
} }
def _normalize_metadata_casefold(values: Optional[Mapping[str, Any]]) -> Dict[str, str]: def _normalize_metadata_casefold(values: Optional[Mapping[str, Any]]) -> Dict[str, Any]:
normalized: Dict[str, str] = {} normalized: Dict[str, Any] = {}
if not values: if not values:
return normalized return normalized
for key, value in values.items(): for key, value in values.items():
@@ -238,6 +238,9 @@ def _normalize_metadata_casefold(values: Optional[Mapping[str, Any]]) -> Dict[st
key_text = str(key).strip().lower() key_text = str(key).strip().lower()
if not key_text: if not key_text:
continue continue
if isinstance(value, (list, tuple, set)):
normalized[key_text] = value
else:
text = str(value).strip() text = str(value).strip()
if text: if text:
normalized[key_text] = text normalized[key_text] = text
@@ -304,10 +307,15 @@ def _split_simple_list(raw: Any) -> List[str]:
return ordered return ordered
def _first_nonempty(*values: Optional[str]) -> Optional[str]: def _first_nonempty(*values: Any) -> Optional[str]:
for value in values: for value in values:
if value is None: if value is None:
continue continue
if isinstance(value, (list, tuple, set)):
items = list(value)
if not items:
continue
value = items[0]
text = str(value).strip() text = str(value).strip()
if text: if text:
return text return text