Skip to content

feat: add transaction() context manager to CoordinodeClient #23

@polaz

Description

@polaz

Feature

Add explicit transaction support to the Python SDK once CoordiNode implements Bolt-level transaction lifecycle (BEGIN / COMMIT / ROLLBACK).

API design

Context manager (preferred):

with client.transaction() as tx:
    tx.cypher("CREATE (n:Person {name: $name})", params={"name": "Alice"})
    tx.cypher("CREATE (n:Person {name: $name})", params={"name": "Bob"})
    # auto-commit on clean exit, auto-rollback on exception

Explicit API:

tx = client.begin_transaction()
try:
    tx.cypher("MERGE (n:Entity {name: $name})", params={"name": "Alice"})
    tx.commit()
except Exception:
    tx.rollback()
    raise

Implementation notes

  • Wire to Bolt BEGIN / COMMIT / ROLLBACK messages once R508 is available
  • CoordinodeClient.transaction() returns a Transaction object that wraps a Bolt session
  • Transaction.cypher() sends queries within the open transaction (no auto-commit per statement)
  • The existing client.cypher() stays as auto-commit shorthand for single statements
  • LlamaIndex and LangChain adapters: evaluate wrapping upsert_nodes + upsert_relations calls in a transaction for atomicity

Gate

Blocked by CoordiNode DB task R508 — Bolt protocol transaction lifecycle (BEGIN / COMMIT / ROLLBACK).
This is Phase 5.1. Do not start SDK implementation until CoordiNode adds Bolt transaction support.

Acceptance criteria

  • client.transaction() context manager works correctly
  • Transaction.cypher() sends queries in-transaction
  • Rollback on exception is automatic
  • Integration test: verify partial write is rolled back on error
  • client.begin_transaction() / tx.commit() / tx.rollback() explicit API
  • Documented in README

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions