API Reference
in_read_only

dbzero.in_read_only()

dbzero-procommercial edition

dbzero.in_read_only() -> bool

Return whether the current execution context is inside a dbzero read_only() block.

This is useful for integration code that needs to reject mutating operations before dispatching them elsewhere, such as RPC, service, or plugin layers that distinguish read methods from mutators.


Parameters

This method takes no parameters.


Returns

  • True if the current execution context is protected by dbzero.read_only().
  • False otherwise.

Examples

def call_service(method, *args):
    if method.is_mutating and db0.in_read_only():
        raise RuntimeError("read_only context forbids mutating service calls")
 
    return method(*args)
 
with db0.read_only():
    # Local integration code can detect the protected non-mutating block.
    assert db0.in_read_only()