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(
215
+
"Field 'item_content' does not appear to be valid JSON"
216
+
)
217
+
json_dump=json.loads(v.json())
218
+
forkey, valueinjson_dump.items():
219
+
ifvalue!=item_content[key]:
220
+
self._raise_value_error(item_content, key, value)
221
+
222
+
@staticmethod
223
+
def_raise_value_error(item_content, key, value):
224
+
"""Raise a ValueError with a message that explains the content/item_content mismatch"""
225
+
ifisinstance(value, list):
226
+
foriteminvalue:
227
+
ifitemnotinitem_content[key]:
229
228
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])})"
229
+
f"Field 'content.{key}' does not match 'item_content.{key}': {item} != {item_content[key]}"
231
230
)
232
-
returnv
231
+
ifisinstance(value, dict):
232
+
foriteminvalue.items():
233
+
ifitemnotinitem_content[key].items():
234
+
raiseValueError(
235
+
f"Field 'content.{key}' does not match 'item_content.{key}': {value} != {item_content[key]}"
236
+
)
237
+
raiseValueError(
238
+
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