Session: How to Clear a Session

To clear session state, stop tracking entities, and remove all pending commands, use the clear method from the advanced session operations.

Syntax

def clear(self) -> None: ...

Example

session.store(Employee(first_name="John", last_name="Doe"))

session.advanced.clear()

session.save_changes()  # nothing will happen