neo4j-contrib / neomodel

An Object Graph Mapper (OGM) for the Neo4j graph database.
https://neomodel.readthedocs.io
MIT License
963 stars 232 forks source link

NodeClassAlreadyDefined when importing Node Class into script #619

Closed rggs closed 2 years ago

rggs commented 2 years ago

I made a python file that defines two classes:

from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,
    UniqueIdProperty, JSONProperty, RelationshipTo, RelationshipFrom)

config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687/database'  # default

class Category(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    date = JSONProperty(default={})

    child_category = RelationshipFrom('Category', 'IS_CHILD')
    parent_category = RelationshipFrom('Category', 'IS_PARENT')

class Page(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty(unique_index=True)
    date = JSONProperty(default={})
    child = RelationshipFrom('Category', 'IS_CHILD')
    preceeds = RelationshipFrom('Page', 'PRECEEDS')
    linked = RelationshipFrom('Page', 'LINKED')

I used the neomodel_install_labels to create these labels, and I can see that they are in fact in the database. I then try to import those classes into another file and make a node:

from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,
    UniqueIdProperty, JSONProperty, RelationshipTo, RelationshipFrom)

from techtreemodel import Page, Category

config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687/database'  # default

aircraft = Page(name='Aircraft').save() # Create

Which fails with the following error:

NodeClassAlreadyDefined: Class techtreemodel.Category with labels Category already defined:
Category --> <class '__main__.Category'>
Page --> <class '__main__.Page'>

This error occurs in the line where I import Category and Page from the techtreemodel.py file. What am I doing wrong here?

rggs commented 2 years ago

This seems to be unique to using an IPython console.

webcoderz commented 1 year ago

is there an easy fix here? i am using this in a streamlit app and keep getting this