activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

NoMethodError on Neo4j::Core::Node in development mode

Open sqpierce opened this issue 5 years ago • 2 comments

neo4j gem version: 9.3.0 neo4j-core version: 8.1.4

I'm having an issue that you appear to have solved back in 2015,

here: https://github.com/neo4jrb/neo4j/issues/717

and

here: https://github.com/neo4jrb/devise-neo4j/issues/16

The error only happens in development mode, and only when a change is made to files and therefore code is reloaded.

The error message, for example, is NoMethodError - undefined method 'name' for #<Neo4j::Core::Node:0x00007f960c7bc858>

where 'name' is one of the properties on one of our nodes (note that the error can happen equally on properties or relationships):

# this is just a snippet
module BitFarm
  class Lesson
    include Neo4j::ActiveNode
    include Neo4j::Timestamps

    self.mapped_label_name = 'Lesson'

    property :name
  end
end

In trying to figure out why we're having this issue, I can only surmise that it might have something to do with the fact that we are using the neo4j gem within a gem of our own (called 'bit_farm'), which is in turn required by our Rails app.

I've tried various things to attempt to address the issue, including setting up a railtie in bit_farm which calls Neo4j::ActiveNode::Labels::Reloading.reload_models! but this does not do anything, as Neo4j::ActiveNode::Labels::Reloading::MODELS_TO_RELOAD appears to be an empty array at that point.

FWIW this was the railtie:

module BitFarm
  class Railtie < ::Rails::Railtie
    config.to_prepare do
      Neo4j::ActiveNode::Labels::Reloading.reload_models!
    end
  end
end

I am fairly certain that the code in neo4j/lib/neo4j/railtie.rb is being executed before the code in our railtie (not sure if that might be a factor).

I have also tried to explicitly load our Lesson class before the query that throws the error (via Kernel#load) and this also has no effect.

I suspect it comes down to something in lib/neo4j/active_node/labels/reloading.rb such as the WRAPPED_CLASSES, but I'm afraid I don't know how to get our classes invited to that party.

Any help or ideas would be greatly appreciated.

sqpierce avatar Jun 05 '19 18:06 sqpierce

Hi, this is still an outstanding issue for us, I wonder if anyone has any thoughts?

Or, perhaps I'm not explaining the problem very well?

sqpierce avatar Sep 03 '19 15:09 sqpierce

I'm experiencing this also. One aspect to our codebase is that we define one of our neo4j models in a separate gem that we then include in our app. When the rails app first boots everything is good, then If I change any file I get this error. For example, I can add an empty line to an unrelated class, reload the page and this error appears. I tried to look into the rails autoloading system but it seems there is no easy way to log reloading errors.

OpenCoderX avatar Sep 11 '19 01:09 OpenCoderX