mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		@@ -12,9 +12,9 @@ BATCH_SIZE = 1000
 | 
				
			|||||||
def process_batch(apps: StateApps, id_start: int, id_end: int, last_id: int) -> None:
 | 
					def process_batch(apps: StateApps, id_start: int, id_end: int, last_id: int) -> None:
 | 
				
			||||||
    Message = apps.get_model('zerver', 'Message')
 | 
					    Message = apps.get_model('zerver', 'Message')
 | 
				
			||||||
    for message in Message.objects.filter(id__gte=id_start, id__lte=id_end).order_by("id"):
 | 
					    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
 | 
					            # 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.
 | 
					            # need to skip those because lxml won't process them.
 | 
				
			||||||
            #
 | 
					            #
 | 
				
			||||||
            # They should safely already have the correct state
 | 
					            # They should safely already have the correct state
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user