Rollback the transaction Discards all changes made within this transaction. This is called automatically when the transaction context exits, so explicit rollback is rarely needed. Raises: TransactionError: If rollback fails Examples:
(self)
| 147 | raise TransactionError(f"Failed to commit: {e}") |
| 148 | |
| 149 | def rollback(self) -> None: |
| 150 | """ |
| 151 | Rollback the transaction |
| 152 | |
| 153 | Discards all changes made within this transaction. This is called |
| 154 | automatically when the transaction context exits, so explicit rollback |
| 155 | is rarely needed. |
| 156 | |
| 157 | Raises: |
| 158 | TransactionError: If rollback fails |
| 159 | |
| 160 | Examples: |
| 161 | >>> with session.transaction() as tx: |
| 162 | ... tx.execute("INSERT (p:Person {name: 'Alice'})") |
| 163 | ... tx.rollback() # Explicit rollback (optional, automatic on exit) |
| 164 | """ |
| 165 | if self._committed: |
| 166 | return # Already committed, nothing to rollback |
| 167 | if self._rolled_back: |
| 168 | return # Already rolled back |
| 169 | |
| 170 | try: |
| 171 | self._session._db.execute(self._session._session_id, "ROLLBACK") |
| 172 | self._rolled_back = True |
| 173 | except Exception as e: |
| 174 | raise TransactionError(f"Failed to rollback: {e}") |
| 175 | |
| 176 | def __enter__(self): |
| 177 | """Context manager entry""" |
no test coverage detected