Skip to content

fix: make graph add relationship writes transactional#1011

Open
wayyoungboy wants to merge 1 commit into
oceanbase:mainfrom
wayyoungboy:fix/issue-1003-graph-add-transaction
Open

fix: make graph add relationship writes transactional#1011
wayyoungboy wants to merge 1 commit into
oceanbase:mainfrom
wayyoungboy:fix/issue-1003-graph-add-transaction

Conversation

@wayyoungboy

Copy link
Copy Markdown
Member

Summary

Partially addresses #1003.

This PR fixes the independent atomicity part of the graph add() issue by putting relationship deletes and relationship inserts in the same SQLAlchemy transaction.

Changes:

  • wraps the add() delete+add relationship write stage in engine.begin()
  • passes the active transaction connection into _delete_entities() and _add_entities()
  • uses the transaction connection for relationship deletion, relationship existence checks, relationship insertion, and final entity-name reads
  • re-raises delete failures inside the transaction path so failures roll back instead of being silently treated as zero deletes
  • preserves the existing non-transaction client path for direct helper calls
  • adds unit coverage for transaction connection propagation, relationship delete, and relationship insert paths

The check-then-create duplicate entity race should be handled separately after #1002 lands, because the correct unique key depends on graph_entities.user_id and should be (user_id, name).

Validation

  • python -m pytest tests/unit/test_oceanbase_graph.py -q
  • python -m pytest tests/unit -q
  • python -m flake8 src/powermem/storage/oceanbase/oceanbase_graph.py tests/unit/test_oceanbase_graph.py --select=F601,F821,E999
  • git diff --check

@wayyoungboy wayyoungboy marked this pull request as ready for review June 11, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant