mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-25 13:10:14 +01:00
Discard invalid StreamField data rather than throwing ValueError
This commit is contained in:
parent
6f37c78c95
commit
b2372c8787
@ -70,7 +70,16 @@ class StreamField(with_metaclass(models.SubfieldBase, models.Field)):
|
||||
elif isinstance(value, StreamValue):
|
||||
return value
|
||||
else: # assume string
|
||||
return self.stream_block.to_python(json.loads(value))
|
||||
try:
|
||||
return self.stream_block.to_python(json.loads(value))
|
||||
except ValueError:
|
||||
# value is not valid JSON; most likely, this field was previously a
|
||||
# rich text field before being migrated to StreamField, and the data
|
||||
# was left intact in the migration. Return an empty stream instead.
|
||||
|
||||
# TODO: keep this raw text data around as a property of the StreamValue
|
||||
# so that it can be retrieved in data migrations
|
||||
return StreamValue(self.stream_block, [])
|
||||
|
||||
def get_prep_value(self, value):
|
||||
return json.dumps(self.stream_block.get_prep_value(value), cls=DjangoJSONEncoder)
|
||||
|
Loading…
Reference in New Issue
Block a user