dbzero.in_read_only()
dbzero-procommercial editiondbzero.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
Trueif the current execution context is protected bydbzero.read_only().Falseotherwise.
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()