When managing configuration changes via PyEZ Config utility, which context manager ensures that changes are automatically rolled back if an exception occurs within the block?
Trap 1: with Config(dev, mode='private') as cu:
Incorrect. Mode specifies private database editing, but automatic rollback on exception requires the context manager itself regardless of mode, though the context manager handles lock/unlock.
Trap 2: try: cu.lock() except: cu.rollback()
Incorrect. While manual try/except works, PyEZ natively provides context manager safety.
Trap 3: cu.commit(rollback_on_error=True)
Incorrect. This parameter does not exist on the commit method in this format.
- A
with Config(dev, mode='private') as cu:
Why it fails: Incorrect. Mode specifies private database editing, but automatic rollback on exception requires the context manager itself regardless of mode, though the context manager handles lock/unlock.
- B
try: cu.lock() except: cu.rollback()
Why it fails: Incorrect. While manual try/except works, PyEZ natively provides context manager safety.
- C
with Config(dev) as cu:
Using `with Config(dev) as cu:` invokes the PyEZ Config context manager, which wraps the candidate configuration in a transaction. If an exception propagates out of the block, the context manager automatically calls `rollback()`, discarding uncommitted changes and satisfying the stem's requirement for automatic rollback on failure.
- D
cu.commit(rollback_on_error=True)
Why it fails: Incorrect. This parameter does not exist on the commit method in this format.