MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / custom_properties_as_dict

Function custom_properties_as_dict

core/utils.py:75–98  ·  view source on GitHub ↗

Normalize a JSONField-backed custom_properties value into a dict. Historical rows (TextField era and early JSONField migration) may store a JSON-encoded string instead of an object. API clients can also submit a string value because JSONField accepts any JSON type. Call this before

(value)

Source from the content-addressed store, hash-verified

73
74
75def custom_properties_as_dict(value):
76 """
77 Normalize a JSONField-backed custom_properties value into a dict.
78
79 Historical rows (TextField era and early JSONField migration) may store a
80 JSON-encoded string instead of an object. API clients can also submit a
81 string value because JSONField accepts any JSON type. Call this before
82 reading or merging custom_properties.
83 """
84 if isinstance(value, dict):
85 return value
86 if isinstance(value, str):
87 try:
88 parsed = json.loads(value)
89 except (ValueError, TypeError):
90 logger.warning(
91 "custom_properties stored as non-JSON string; ignoring: %r",
92 value[:100],
93 )
94 return {}
95 return parsed if isinstance(parsed, dict) else {}
96 if value is None:
97 return {}
98 return {}
99
100
101def ensure_custom_properties_dict(value):

Callers 9

saveMethod · 0.90
saveMethod · 0.90
saveMethod · 0.90
test_dict_passthroughMethod · 0.90

Calls

no outgoing calls