activegraph
activegraph copied to clipboard
undefined method current for Neo4j::Transaction:Module
I've got an exception popping up during a transaction and it looks like neo4j is throwing another exception while trying to process that one. It looks like a simple method reference error, but the code in question is old (2-3 years) and it seems unlikely that I'm the first person in that time to exercise this code branch which makes me suspicious. What's going on?
Here's my stack trace from my application:
NoMethodError: undefined method `current' for Neo4j::Transaction:Module
Did you mean? current_for
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/shared/persistence.rb:91:in `rescue in create_or_update'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/shared/persistence.rb:95:in `create_or_update'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/shared/callbacks.rb:48:in `block in create_or_update'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_save_callbacks'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/shared/callbacks.rb:48:in `create_or_update'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/active_node/persistence.rb:28:in `block in save'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/active_node/persistence.rb:96:in `block in cascade_save'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-core-7.2.3/lib/neo4j/transaction.rb:132:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/active_node/persistence.rb:95:in `cascade_save'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/active_node/persistence.rb:26:in `save'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/shared/validations.rb:18:in `save'
/app/vendor/bundle/ruby/2.3.0/gems/neo4j-7.1.2/lib/neo4j/active_node/persistence.rb:51:in `save!'
... application code ...
persistence.rb#L91 hasn't changed in 3 years and Transaction.current_for hasn't changed in 2 years so this doesn't seem to be a recently-introduced bug or regression.
Code example (inline, gist, or repo)
require 'neo4j'
require 'neo4j-core'
class TestClass
include Neo4j::ActiveNode
property :name, type: String, constraint: :unique
end
begin
Neo4j::Session.open(:server_db, ENV["NEO4J_URL"])
test = TestClass.create(name: 'foo')
puts "created: #{test}"
test2 = TestClass.create(name: 'foo') # throws ConstraintViolationError
puts "created: #{test2}" # never reached
rescue Exception => error
puts "Rescued Exception: #{error}"
end
Expected
This should rescue the Neo4j::Server::CypherResponse::ConstraintViolationError
Actual
Program output:
created: #<TestClass:0x00000002d29c98>
Rescued Exception: undefined method `current' for Neo4j::Transaction:Module
Did you mean? current_for
Runtime information:
Neo4j database version: 3.0.6
neo4j
gem version: 7.1.2
neo4j-core
gem version: 7.2.3
That's certainly odd. Did anything change or get upgraded?
I notice that you mention you're using version 7.2.3
of the neo4j-core
gem. When the neo4j
gem was upgraded to version 8.0 the neo4j-core
gem was upgraded to 7.0 at the same time. I think that 7.x of the neo4j
gem should be more compatible with the 6.x
series of the neo4j-core
gem. If that's the case I can certainly formalize that in the gemspec
of the neo4j
gem so that other people don't run into this.
You might also try updating the neo4j
gem to the 8.x series, but the neo4j
8.0 and neo4j-core
7.0 updates contained a lot of changes (and even come with an upgrade guide), so I would try the downgrade of neo4j-core
first
Thanks for the quick response!
Did anything change or get upgraded?
Yes, we were originally using gem 'neo4j', '~> 7.0.5'
and just whatever version of neo4j-core it brought in. What changed was that we needed explicit transaction support so we upgraded neo4j-core to '~> 7.0'
Lacking any indication that these two versions were incompatible, we kept neo4j as it was. I recently updated it to 'neo4j', '>= 7.0.5', '< 8.0'
to see if that would resolve the current/current_for issue, without success.
Since we need the 7.x version of neo4j-core, I'll try upgrading our neo4j gem to 8.x
I would definitely suggest formalizing the gemspecs to indicate which versions of the two gems are compatible with each other.
Ah, looks like I was ahead of myself... It looks like version the latest versions in the 7.0.x series all have < 7.0.0
in the gemspec
s for neo4j-core
. Looking through rubygems.org it looks like this was introduced in versions 7.0.15 and 7.1.3 on August 18th of last year.
I believe the neo4j-core
gem has had explicit transaction support for a while though (but I might just be misunderstanding what that means). If you stay on the 7.x line I'd suggest at least upgrading to 7.0.16, but 7.2.3 should also be a pretty easy upgrade too (we try to stick to semantic versioning). We also try to keep careful CHANGELOGs for neo4j
and neo4j-core
so you can check out what's changed
Hi Brian, (This project is active again after being on hold for a few months.)
Our project was originally built with neo4j (7.0.14) and neo4j-core (6.1.4) - the currently stable versions of each gem at the time. When we introduced transactions into our application code, we had to update the neo4j-core gem to 7.x because the transaction.closed?
method was not available prior to that version (introduced here). And since the Gemspec for neo4j (7.0.14) did not yet have the neo4j-core version locked down, everything seemed ok to proceed at the time.
I am trying the downgrade you suggested and wondering what my options are for checking if a transaction was closed successfully with the 6.1.x version of the cypher transaction. Is expired?
semantically equivalent to closed?
? Thanks in advance for your support.