Display information that a problem has been found but ignored (and therefore the migration is considered ok)
This commit is contained in:
1 parent
aa8043db74
commit
85b9abdbc3
2 files changed
+37
-22
No files matched your search
@@ -121,10 +121,16 @@ class MigrationLinter(object):
|
||||
|
||||
sql_statements = self.get_sql(app_label, migration_name)
|
||||
exclude_migration_tests = self.exclude_migration_tests or []
|
||||
errors = analyse_sql_statements(sql_statements, exclude_migration_tests)
|
||||
errors, ignored = analyse_sql_statements(
|
||||
sql_statements, exclude_migration_tests
|
||||
)
|
||||
|
||||
if not errors:
|
||||
print("OK")
|
||||
if ignored:
|
||||
print("OK (ignored)")
|
||||
self.print_errors(ignored)
|
||||
else:
|
||||
print("OK")
|
||||
self.nb_valid += 1
|
||||
if self.should_use_cache():
|
||||
self.new_cache[md5hash] = {"result": "OK"}
|
||||
|
||||
@@ -70,28 +70,37 @@ migration_tests = (
|
||||
)
|
||||
|
||||
|
||||
def get_migration_tests(exclude_migration_tests):
|
||||
for test in migration_tests:
|
||||
if test["code"] in exclude_migration_tests:
|
||||
continue
|
||||
yield test
|
||||
|
||||
|
||||
def analyse_sql_statements(sql_statements, exclude_migration_tests):
|
||||
errors = []
|
||||
errors, ignored = [], []
|
||||
for statement in sql_statements:
|
||||
for test in get_migration_tests(exclude_migration_tests):
|
||||
for test in migration_tests:
|
||||
if test["fn"](statement, errors=errors):
|
||||
logger.debug("Testing {0} -- ERROR".format(statement))
|
||||
table_search = re.search("TABLE `([^`]*)`", statement, re.IGNORECASE)
|
||||
col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE)
|
||||
err = {
|
||||
"err_msg": test["err_msg"],
|
||||
"code": test["code"],
|
||||
"table": table_search.group(1) if table_search else None,
|
||||
"column": col_search.group(1) if col_search else None,
|
||||
}
|
||||
errors.append(err)
|
||||
if test["code"] in exclude_migration_tests:
|
||||
logger.debug("Testing {0} -- IGNORED".format(statement))
|
||||
table_search = re.search(
|
||||
"TABLE `([^`]*)`", statement, re.IGNORECASE
|
||||
)
|
||||
col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE)
|
||||
err = {
|
||||
"err_msg": test["err_msg"],
|
||||
"code": test["code"],
|
||||
"table": table_search.group(1) if table_search else None,
|
||||
"column": col_search.group(1) if col_search else None,
|
||||
}
|
||||
ignored.append(err)
|
||||
else:
|
||||
logger.debug("Testing {0} -- ERROR".format(statement))
|
||||
table_search = re.search(
|
||||
"TABLE `([^`]*)`", statement, re.IGNORECASE
|
||||
)
|
||||
col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE)
|
||||
err = {
|
||||
"err_msg": test["err_msg"],
|
||||
"code": test["code"],
|
||||
"table": table_search.group(1) if table_search else None,
|
||||
"column": col_search.group(1) if col_search else None,
|
||||
}
|
||||
errors.append(err)
|
||||
else:
|
||||
logger.debug("Testing {0} -- PASSED".format(statement))
|
||||
return errors
|
||||
return errors, ignored
|
||||
Reference in new issue
Block a user