Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Context manager for a scoped transaction log

Python data engineering interview problem. Difficulty: advanced. Pattern: OOP. About 20 minutes. Part of the Pro drill bank.

A job writes a transaction log that must close even if the body fails. A context manager is the Python way to guarantee setup/teardown.

Implement a context manager that records a scoped transaction log as the tests specify.

Requirements

  • Enter writes a start marker.
  • Exit writes an end marker even if an op fails, unless tests want a different policy.

Constraints

  • ops: operations to run inside the scope.
  • Exceptions inside should follow the tests (swallow vs propagate).

Examples

Input: run_transaction(['ok', 'ok']) Output: {'status': 'committed', 'ran': 2} This input follows the stated rules and produces this output.

Topics: lakebench, python, OOP.

More Python interview questions · All interview problems · Learn data engineering

advanced

Context manager for a scoped transaction log

Interview-style drill: Write a context manager that records whether a block of operations completed or raised an error.

Implement a context manager that records a scoped transaction log as the tests specify.