Make data migration model import check a bit less strict

It now allows:
* get_model(...) calls with one parameter only
* allows the variable name to be not the same as the model name itself (this will become a warning)
This commit is contained in:
David-Wobrock authored and David Wobrock committed 2020-11-26 19:02:57 +01:00
1 parent 5e26d9a910
commit a68ff7c306
3 files changed
+47 -4

No files matched your search

+4 -4
View File
@@ -461,15 +461,15 @@ class MigrationLinter(object):
model_object_regex = re.compile(r"[^a-zA-Z]?([a-zA-Z0-9]+?)\.objects")
function_name = code.__name__
reverse_code_source = inspect.getsource(code)
source_code = inspect.getsource(code)
called_models = model_object_regex.findall(reverse_code_source)
called_models = model_object_regex.findall(source_code)
issues = []
for model in called_models:
has_get_model_call = (
re.search(
r"get_model\(\s*?.*?,.*?{}.+?\s*?\)".format(model),
reverse_code_source,
r"{}.*= +\w+\.get_model\(".format(model),
source_code,
)
is not None
)