fix(proxy): stop the legacy resolver marking migrations applied after a failed diff

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
jesus 2026-09-22 18:57:27 +00:00
parent f3a0bb7249
commit c802016859
2 changed files with 22 additions and 1 deletions

View file

@ -473,8 +473,10 @@ class ProxyExtrasDBManager:
env=_get_prisma_env(),
)
except subprocess.CalledProcessError as e:
diff_sql_path.unlink(missing_ok=True)
logger.warning(f"Failed to generate migration diff: {e.stderr}")
except subprocess.TimeoutExpired:
diff_sql_path.unlink(missing_ok=True)
logger.warning("Migration diff generation timed out.")
# check if the migration was created

View file

@ -538,7 +538,7 @@ class _FakeCompleted:
class TestResolveAllMigrationsLedger:
def _run(self, monkeypatch, tmp_path, partitioned, execute_fails):
def _run(self, monkeypatch, tmp_path, partitioned, execute_fails, diff_fails=False):
import subprocess as subprocess_module
import litellm_proxy_extras.utils as utils_module
@ -555,9 +555,19 @@ class TestResolveAllMigrationsLedger:
)
calls = []
for migration_name in (
"20250326162113_baseline",
"20260520120000_add_mcp_env_vars",
):
migration_dir = tmp_path / migration_name
migration_dir.mkdir(parents=True)
(migration_dir / "migration.sql").write_text("SELECT 1;")
def fake_run(cmd, **kwargs):
calls.append(cmd)
if "diff" in cmd:
if diff_fails:
raise subprocess_module.CalledProcessError(1, cmd, stderr="P1001")
kwargs["stdout"].write(_PARTITIONED_DRIFT_SQL)
return _FakeCompleted()
if "execute" in cmd:
@ -599,6 +609,15 @@ class TestResolveAllMigrationsLedger:
calls = self._run(monkeypatch, tmp_path, partitioned=False, execute_fails=False)
assert self._executed_sql(calls) == _PARTITIONED_DRIFT_SQL
def test_failed_diff_runs_the_migration_files_directly_and_marks_nothing_applied(self, monkeypatch, tmp_path):
calls = self._run(monkeypatch, tmp_path, partitioned=False, execute_fails=False, diff_fails=True)
executed_files = [c[c.index("--file") + 1] for c in calls if isinstance(c, list) and "execute" in c]
assert executed_files == [
str(tmp_path / "20250326162113_baseline" / "migration.sql"),
str(tmp_path / "20260520120000_add_mcp_env_vars" / "migration.sql"),
]
assert self._resolved(calls) == []
class TestPartitionedSpendLogsPushGuard:
def _forbid_subprocess(self, monkeypatch):