You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Check that the content matches the serialized item_content"""
206
207
item_type=values["item_type"]
207
-
ifitem_type==ItemType.inline:
208
-
try:
209
-
item_content=json.loads(values["item_content"])
210
-
exceptJSONDecodeError:
211
-
raiseValueError(
212
-
"Field 'item_content' does not appear to be valid JSON"
213
-
)
214
-
json_dump=json.loads(v.json())
215
-
forkey, valueinjson_dump.items():
216
-
ifvalue!=item_content[key]:
217
-
ifisinstance(value, list):
218
-
foriteminvalue:
219
-
ifitemnotinitem_content[key]:
220
-
raiseValueError(
221
-
f"Field 'content.{key}' does not match 'item_content.{key}': {item} != {item_content[key]}"
222
-
)
223
-
ifisinstance(value, dict):
224
-
foriteminvalue.items():
225
-
ifitemnotinitem_content[key].items():
226
-
raiseValueError(
227
-
f"Field 'content.{key}' does not match 'item_content.{key}': {value} != {item_content[key]}"
228
-
)
208
+
ifitem_type!=ItemType.inline:
209
+
returnv
210
+
211
+
try:
212
+
item_content=json.loads(values["item_content"])
213
+
exceptJSONDecodeError:
214
+
raiseValueError("Field 'item_content' does not appear to be valid JSON")
215
+
json_dump=json.loads(v.json())
216
+
forkey, valueinjson_dump.items():
217
+
ifvalue!=item_content[key]:
218
+
self._raise_value_error(item_content, key, value)
219
+
220
+
@staticmethod
221
+
def_raise_value_error(item_content, key, value):
222
+
"""Raise a ValueError with a message that explains the content/item_content mismatch"""
223
+
ifisinstance(value, list):
224
+
foriteminvalue:
225
+
ifitemnotinitem_content[key]:
229
226
raiseValueError(
230
-
f"Field 'content.{key}' does not match 'item_content.{key}': {value} != {item_content[key]} or type mismatch ({type(value)} != {type(item_content[key])})"
227
+
f"Field 'content.{key}' does not match 'item_content.{key}': {item} != {item_content[key]}"
231
228
)
232
-
returnv
229
+
ifisinstance(value, dict):
230
+
foriteminvalue.items():
231
+
ifitemnotinitem_content[key].items():
232
+
raiseValueError(
233
+
f"Field 'content.{key}' does not match 'item_content.{key}': {value} != {item_content[key]}"
234
+
)
235
+
raiseValueError(
236
+
f"Field 'content.{key}' does not match 'item_content.{key}': {value} != {item_content[key]} or type mismatch ({type(value)} != {type(item_content[key])})"
0 commit comments