Skip to content

Commit a07c6b4

Browse files
committed
test: cover PostgreSQL rollback compensation boundary
1 parent 9da253d commit a07c6b4

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎tests/test_inplace_transform.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,41 @@ def test_capability_declares_dolt_owned_versioning() -> None:
507507
assert declaration["creates_persistent_data_copy"] is False
508508
assert declaration["openstatspec_rollback_or_version_history"] is False
509509
assert declaration["performs_dolt_commit"] is False
510+
511+
def test_postgresql_rollback_skips_unlocked_compensation(
512+
tmp_path, monkeypatch,
513+
) -> None:
514+
database_url = f"sqlite:///{tmp_path / 'postgres-rollback.sqlite'}"
515+
monkeypatch.setattr(
516+
inplace_transform,
517+
"effective_profile",
518+
lambda _url: (SimpleNamespace(name="postgresql"), {}),
519+
)
520+
521+
def fail_after_schema_change(
522+
_connection, *, mutation_journal, **_kwargs,
523+
):
524+
mutation_journal["added_columns"] = ["score_band"]
525+
raise RuntimeError("simulated transactional failure")
526+
527+
monkeypatch.setattr(
528+
inplace_transform, "_apply_plan_on_connection", fail_after_schema_change,
529+
)
530+
monkeypatch.setattr(
531+
inplace_transform,
532+
"_compensate_failed_apply",
533+
lambda *_args, **_kwargs: pytest.fail(
534+
"PostgreSQL rollback must not run unlocked compensation"
535+
),
536+
)
537+
538+
with pytest.raises(RuntimeError, match="simulated transactional failure"):
539+
inplace_transform._run_in_place_submission(
540+
database_url=database_url,
541+
dataset_id="dataset",
542+
actor="test-agent",
543+
prepare=lambda _connection, _dataset_id: _submission(
544+
"RECODE score (1 = 0) INTO score_band."
545+
),
546+
)
547+

0 commit comments

Comments
 (0)