Avoid using SmartFilter during migrations (#14786)

Our migrations that touch roles tend to bring in our real models via
migration_utils.set_current_apps_for_migrations, and that can have
some undesirable side-effects.
This commit is contained in:
Jeff Bradberry
2024-02-12 10:48:58 -05:00
committed by GitHub
parent 55c6a319dc
commit 36f3b46726

View File

@@ -5,6 +5,7 @@
import copy import copy
import json import json
import re import re
import sys
import urllib.parse import urllib.parse
from jinja2 import sandbox, StrictUndefined from jinja2 import sandbox, StrictUndefined
@@ -406,11 +407,13 @@ class SmartFilterField(models.TextField):
# https://docs.python.org/2/library/stdtypes.html#truth-value-testing # https://docs.python.org/2/library/stdtypes.html#truth-value-testing
if not value: if not value:
return None return None
value = urllib.parse.unquote(value) # avoid doing too much during migrations
try: if 'migrate' not in sys.argv:
SmartFilter().query_from_string(value) value = urllib.parse.unquote(value)
except RuntimeError as e: try:
raise models.base.ValidationError(e) SmartFilter().query_from_string(value)
except RuntimeError as e:
raise models.base.ValidationError(e)
return super(SmartFilterField, self).get_prep_value(value) return super(SmartFilterField, self).get_prep_value(value)