Fix #209 - Raise when getting SQL statements fail.
This commit is contained in:
1 parent
74a7ee9239
commit
bef47906d1
4 files changed
+34
-7
No files matched your search
+5
-1
@@ -1,5 +1,9 @@
|
||||
## 4.1.1 (unreleased)
|
||||
## 5.0.0 (unreleased)
|
||||
|
||||
- **Breaking change**: stop silently ignoring when the internal `sqlmigrate` call fails and the linter cannot analyse the migration.
|
||||
Instead, the linter crashes and lets the `sqlmigrate` error raise, in order to avoid letting a problematic migration pass.
|
||||
One common reason for such an error is the SQL generation which requires the database to be actually migrated in order to fetch actual constraint names from it.
|
||||
The crash is a sign to double-check the migration. But if you are certain the migration is safe, you can ignore it (issue #209)
|
||||
- Fixed `RunPython` model import check when using a `through` object like `MyModel.many_to_many.through.objects.filter(...)` (issue #218)
|
||||
|
||||
## 4.1.0
|
||||
|
||||
@@ -315,14 +315,11 @@ class MigrationLinter(object):
|
||||
)
|
||||
except (ValueError, ProgrammingError):
|
||||
logger.warning(
|
||||
(
|
||||
"Error while executing sqlmigrate on (%s, %s). "
|
||||
"Continuing execution with empty SQL."
|
||||
),
|
||||
"Error while executing sqlmigrate on (%s, %s).",
|
||||
app_label,
|
||||
migration_name,
|
||||
)
|
||||
sql_statement = ""
|
||||
raise
|
||||
return sql_statement.splitlines()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -8,6 +8,11 @@ from django.test.utils import override_settings
|
||||
class LintMigrationsCommandTestCase(TransactionTestCase):
|
||||
databases = {"default", "sqlite"}
|
||||
|
||||
def setUp(self):
|
||||
call_command("migrate", "app_unique_together", "0002")
|
||||
self.addCleanup(call_command, "migrate", "app_unique_together")
|
||||
super().setUp()
|
||||
|
||||
def test_plain(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
call_command("lintmigrations")
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import unittest
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
|
||||
from django_migration_linter import MigrationLinter
|
||||
from tests import fixtures
|
||||
@@ -9,7 +10,20 @@ from tests import fixtures
|
||||
|
||||
class BaseBackwardCompatibilityDetection(object):
|
||||
def setUp(self, *args, **kwargs):
|
||||
self.database = next(iter(self.databases))
|
||||
self.test_project_path = os.path.dirname(settings.BASE_DIR)
|
||||
call_command(
|
||||
"migrate",
|
||||
"app_unique_together",
|
||||
"0002",
|
||||
database=self.database,
|
||||
)
|
||||
self.addCleanup(
|
||||
call_command,
|
||||
"migrate",
|
||||
"app_unique_together",
|
||||
database=self.database,
|
||||
)
|
||||
return super(BaseBackwardCompatibilityDetection, self).setUp(*args, **kwargs)
|
||||
|
||||
def _test_linter_finds_errors(self, app=None, commit_id=None):
|
||||
@@ -25,7 +39,7 @@ class BaseBackwardCompatibilityDetection(object):
|
||||
def _launch_linter(self, app=None, commit_id=None):
|
||||
linter = MigrationLinter(
|
||||
self.test_project_path,
|
||||
database=next(iter(self.databases)),
|
||||
database=self.database,
|
||||
no_cache=True,
|
||||
)
|
||||
linter.lint_all_migrations(app_label=app, git_commit_id=commit_id)
|
||||
@@ -91,6 +105,13 @@ class BaseBackwardCompatibilityDetection(object):
|
||||
def test_with_git_ref(self):
|
||||
self._test_linter_finds_errors(commit_id="v0.1.4")
|
||||
|
||||
def test_failing_get_sql(self):
|
||||
call_command("migrate", "app_unique_together", database=self.database)
|
||||
|
||||
linter = MigrationLinter(database=self.database)
|
||||
with self.assertRaises(ValueError):
|
||||
linter.get_sql("app_unique_together", "0003")
|
||||
|
||||
|
||||
class SqliteBackwardCompatibilityDetectionTestCase(
|
||||
BaseBackwardCompatibilityDetection, unittest.TestCase
|
||||
|
||||
Reference in new issue
Block a user