Allow ignoring sqlmigrate errors.
This commit is contained in:
1 parent
a3acff2fef
commit
b15924ca0f
7 files changed
+55
-7
No files matched your search
@@ -175,6 +175,7 @@ class Command(BaseCommand):
|
||||
all_warnings_as_errors=all_warnings_as_errors,
|
||||
no_output=options["verbosity"] == 0,
|
||||
analyser_string=options["sql_analyser"],
|
||||
ignore_sqlmigrate_errors=options["ignore_sqlmigrate_errors"],
|
||||
)
|
||||
linter.lint_all_migrations(
|
||||
app_label=options["app_label"],
|
||||
|
||||
@@ -52,6 +52,7 @@ class Command(MakeMigrationsCommand):
|
||||
self.exclude_migrations_tests = options["exclude_migration_tests"]
|
||||
self.warnings_as_errors = options["warnings_as_errors"]
|
||||
self.sql_analyser = options["sql_analyser"]
|
||||
self.ignore_sqlmigrate_errors = options["ignore_sqlmigrate_errors"]
|
||||
configure_logging(options["verbosity"])
|
||||
return super().handle(*app_labels, **options)
|
||||
|
||||
@@ -92,6 +93,7 @@ class Command(MakeMigrationsCommand):
|
||||
warnings_as_errors_tests=warnings_as_errors_tests,
|
||||
all_warnings_as_errors=all_warnings_as_errors,
|
||||
analyser_string=self.sql_analyser,
|
||||
ignore_sqlmigrate_errors=self.ignore_sqlmigrate_errors,
|
||||
)
|
||||
|
||||
for app_label, app_migrations in changes.items():
|
||||
|
||||
@@ -40,6 +40,12 @@ def register_linting_configuration_options(parser: CommandParser) -> None:
|
||||
help="select the SQL analyser",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--ignore-sqlmigrate-errors",
|
||||
action="store_true",
|
||||
help="ignore failures of sqlmigrate command",
|
||||
)
|
||||
|
||||
|
||||
def configure_logging(verbosity: int) -> None:
|
||||
logger = logging.getLogger("django_migration_linter")
|
||||
|
||||
@@ -63,6 +63,7 @@ class MigrationLinter:
|
||||
all_warnings_as_errors: bool = False,
|
||||
no_output: bool = False,
|
||||
analyser_string: str | None = None,
|
||||
ignore_sqlmigrate_errors: bool = False,
|
||||
):
|
||||
# Store parameters and options
|
||||
self.django_path = path
|
||||
@@ -86,6 +87,7 @@ class MigrationLinter:
|
||||
settings.DATABASES[self.database]["ENGINE"],
|
||||
analyser_string=analyser_string,
|
||||
)
|
||||
self.ignore_sqlmigrate_errors = ignore_sqlmigrate_errors
|
||||
|
||||
# Initialise counters
|
||||
self.reset_counters()
|
||||
@@ -321,13 +323,24 @@ class MigrationLinter:
|
||||
database=self.database,
|
||||
stdout=dev_null,
|
||||
)
|
||||
except (ValueError, ProgrammingError):
|
||||
logger.warning(
|
||||
"Error while executing sqlmigrate on (%s, %s).",
|
||||
app_label,
|
||||
migration_name,
|
||||
)
|
||||
raise
|
||||
except (ValueError, ProgrammingError) as err:
|
||||
if self.ignore_sqlmigrate_errors:
|
||||
logger.warning(
|
||||
"Error while executing sqlmigrate on (%s, %s) with exception: %s. "
|
||||
"Continuing execution with empty SQL.",
|
||||
app_label,
|
||||
migration_name,
|
||||
str(err),
|
||||
)
|
||||
sql_statement = ""
|
||||
else:
|
||||
logger.warning(
|
||||
"Error while executing sqlmigrate on (%s, %s) with exception: %s.",
|
||||
app_label,
|
||||
migration_name,
|
||||
str(err),
|
||||
)
|
||||
raise
|
||||
return sql_statement.splitlines()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user