Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get node based off of parent node #611

Open
you-randomly opened this issue Mar 16, 2022 · 3 comments
Open

can't get node based off of parent node #611

you-randomly opened this issue Mar 16, 2022 · 3 comments

Comments

@you-randomly
Copy link

i need to be able get a node based on it's parent type as i don't know it's child label during the call

my code is set up as such:

from neomodel import (StructuredNode, StringProperty, IntegerProperty,
    UniqueIdProperty, RelationshipTo)

class Device(StructuredNode):
        __abstract_node__ = True
        device_id = UniqueIdProperty()
        hostname = StringProperty(unique_index=True)
        vendor = StringProperty()
        ip = StringProperty()
        version = StringProperty()
        hardware = StringProperty()
        features = StringProperty()

from neo4j_device import Device

class Server(Device):
        pass

when i call

Server.nodes.first_or_none(device_id=device_id)

i get a node as expected

however when i call

Device.nodes.first_or_none(device_id=device_id)

i get the following error

raise NodeClassNotDefined(a_result_attribute[1], self._NODE_CLASS_REGISTRY)
neomodel.exceptions.NodeClassNotDefined: <exception str() failed>

i've checked in neo4j and the node can be matched on either (:Server) or (:Device)

@johnkendall
Copy link

I have the same issue. Cannot get a result with neomodel, works fine with CYPHER.

@mariusconjeaud
Copy link
Collaborator

Multiple node labels used to not be supported in neomodel. Can you check with the latest release 5.1.0, creating your Server class, setting __optional_labels__ to 'Device' ? As shown here in the docs.

Not sure if it fixes it but it's definitely worth a try.

@alanbuxton
Copy link

alanbuxton commented Aug 21, 2023

An alternative, assuming the node you require has both Device and Server labels is not to use __abstract_node__ = True

Setting abstract node True means that this class isn't used as a label in neo4j.

if hasattr(scls, "__label__") and not hasattr(scls, "__abstract_node__")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants