Skip to content

Avoids the usage of Transaction#open?#1736

Merged
klobuczek merged 2 commits into12from
transaction_open
Mar 16, 2026
Merged

Avoids the usage of Transaction#open?#1736
klobuczek merged 2 commits into12from
transaction_open

Conversation

@klobuczek
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ActiveGraph’s transaction handling to avoid calling Neo4j::Driver::Transaction#open? and tightens the supported neo4j-ruby-driver version range to avoid incompatible 6.x releases.

Changes:

  • Removes reliance on Transaction#open? when deciding whether to reuse an existing transaction.
  • Ensures the thread-local tx reference is cleared after transaction work completes.
  • Adds an upper bound to the neo4j-ruby-driver dependency to prevent installing 6.x (including prereleases).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/active_graph/transactions.rb Adjusts transaction reuse logic, changes lock_node behavior, and clears tx in an ensure block.
activegraph.gemspec Pins neo4j-ruby-driver to < 6.0.0.a to avoid 6.x compatibility issues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@@ -29,13 +29,13 @@ def read_transaction(**config, &block)
alias transaction write_transaction

def lock_node(node)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are specs covering .transaction/.write_transaction/rollback behavior, but nothing appears to assert the intended semantics of lock_node (e.g., that it is a no-op unless a transaction is active, and that it runs within the current transaction when one exists). Adding a focused spec here would help prevent regressions around transaction scoping/locking behavior.

Suggested change
def lock_node(node)
def lock_node(node)
return unless tx

Copilot uses AI. Check for mistakes.
Comment thread activegraph.gemspec Outdated
s.add_dependency('activemodel')
s.add_dependency('i18n', '!= 1.8.8') # https://github.com/jruby/jruby/issues/6547
s.add_dependency('neo4j-ruby-driver', '>= 5.7.0.alpha.3')
s.add_dependency('neo4j-ruby-driver', '>= 5.7.0.alpha.3', '< 6.0.0.a')
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upper bound '< 6.0.0.a' is a non-obvious RubyGems versioning trick (it effectively excludes 6.0.0 prereleases as well as 6.0.0). Consider adding a short inline comment explaining why this specific bound is needed (e.g., to avoid pulling 6.x prereleases that remove Transaction#open?), so future maintainers don’t “simplify” it incorrectly.

Suggested change
s.add_dependency('neo4j-ruby-driver', '>= 5.7.0.alpha.3', '< 6.0.0.a')
s.add_dependency('neo4j-ruby-driver', '>= 5.7.0.alpha.3', '< 6.0.0.a') # '< 6.0.0.a' excludes 6.0.0 and its prereleases (6.x removes Transaction#open?)

Copilot uses AI. Check for mistakes.
@@ -29,13 +29,13 @@ def read_transaction(**config, &block)
alias transaction write_transaction

def lock_node(node)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock_node previously only executed the write (REMOVE) when a transaction was active. With the guard removed, calling this method outside an active transaction will execute and commit an auto-transaction, which won't hold a lock beyond that single query and may also remove an existing _AGLOCK_ property unexpectedly. Consider restoring the guard using the thread-local tx presence (e.g., return unless tx) so this only runs when it can actually lock within the current transaction.

Suggested change
def lock_node(node)
def lock_node(node)
return unless tx

Copilot uses AI. Check for mistakes.
nsauk
nsauk previously approved these changes Mar 3, 2026
@klobuczek klobuczek merged commit 85bd835 into 12 Mar 16, 2026
16 of 21 checks passed
@klobuczek klobuczek deleted the transaction_open branch March 16, 2026 21:41
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.

3 participants