migrations: Fix possible 0257_fix_has_link_attribute.py failure.

While it should be an invariant that message.rendered_content is never
None for a row saved to the database, it is possible for that
invariant to be violated, likely including due to bugs in previous
versions of data import/export tools.

While it'd be ideal for such messages to be rendered to fix the
invariant, it doesn't make sense for this has_link migration to crash
because of such a corrupted row, so we apply the similar policy we
already have for rendered_content="".
This commit is contained in:
Iam-VM 2021-08-02 14:42:48 +05:30 committed by Tim Abbott
parent f1d5f3904d
commit 285e10fe2f
1 changed files with 2 additions and 2 deletions

View File

@ -13,9 +13,9 @@ BATCH_SIZE = 1000
def process_batch(apps: StateApps, id_start: int, id_end: int, last_id: int) -> None:
Message = apps.get_model("zerver", "Message")
for message in Message.objects.filter(id__gte=id_start, id__lte=id_end).order_by("id"):
if message.rendered_content == "":
if message.rendered_content in ["", None]:
# There have been bugs in the past that made it possible
# for a message to have "" as its rendered_content; we
# for a message to have "" or None as its rendered_content; we
# need to skip those because lxml won't process them.
#
# They should safely already have the correct state