mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 12:03:46 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import re2
 | |
| from django.db import migrations
 | |
| from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 | |
| from django.db.migrations.state import StateApps
 | |
| 
 | |
| 
 | |
| def delete_re2_invalid(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
 | |
|     options = re2.Options()
 | |
|     options.log_errors = False
 | |
| 
 | |
|     RealmFilter = apps.get_model("zerver", "RealmFilter")
 | |
|     found_errors = False
 | |
|     for linkifier in RealmFilter.objects.all():
 | |
|         try:
 | |
|             re2.compile(linkifier.pattern, options=options)
 | |
|         except re2.error:
 | |
|             if not found_errors:
 | |
|                 print()
 | |
|             found_errors = True
 | |
|             print(
 | |
|                 f"Deleting linkifier {linkifier.id} in realm {linkifier.realm.string_id} which is not compatible with new re2 engine:"
 | |
|             )
 | |
|             print(f"  {linkifier.pattern} -> {linkifier.url_format_string}")
 | |
|             linkifier.delete()
 | |
| 
 | |
| 
 | |
| class Migration(migrations.Migration):
 | |
|     dependencies = [
 | |
|         ("zerver", "0325_alter_realmplayground_unique_together"),
 | |
|     ]
 | |
| 
 | |
|     operations = [
 | |
|         migrations.RunPython(
 | |
|             delete_re2_invalid,
 | |
|             reverse_code=migrations.RunPython.noop,
 | |
|             elidable=True,
 | |
|         )
 | |
|     ]
 |