-
Notifications
You must be signed in to change notification settings - Fork 234
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
Use same relation type between different relationship classes #655
Comments
The current 4.0.8 release has a bug already fixed in the master branch. You can use our .whl package to work around it until the following release (whenever it finally comes): |
With master branch ( 13445c4 ), this bug occurs. |
Looking at the code, this looks like the expected behaviour to me, in the sense that we prevent a given relationship type (in the Neo4j sense) to be used for two completely unrelated relationship objects. Because then, you might have the same type for two relationships but completely different property sets. This is technically possible in Neo4j, and is also acceptable if you're in control of your data model ; so even though the issue you describe is expected behaviour, I am not sure it is desired behaviour. I see many use cases where we want to use the same relationship type even though it's a different domain object. For example :
The above won't be accepted by neomodel if you make HAS_VERSION a direct child of StructuredRel. And... this is where I see a real bug : if your neomodel classes defining these two HAS_VERSION relationships are not direct children of StructuredRel (but still unrelated to each other), then it's accepted by neomodel. class VersionBaseRel(StructuredRel):
pass
class VersionARel(VersionBaseRel):
pass
class VersionBRel(VersionBaseRel):
pass
class NodeA(StructuredNode):
version = RelationshipTo("NodeAVersion", "HAS_VERSION", VersionARel)
class NodeAVersion(StructuredNode):
pass
class NodeB(StructuredNode):
version = RelationshipTo("NodeBVersion", "HAS_VERSION", VersionBRel)
class NodeBVersion(StructuredNode):
pass So, to summarize... I think there is some thinking to be done, and some fixing regardless of what we decide. The question being : do we want to be opinionated and refuse users to give different relationships the same type (relationships being defined by a type + the labels of the two nodes it connects) ; or we want to allow freedom on that. What do you think ? For reference, the part of the code which is at stake here : # If the relationship mapping exists then it is attempted
# to be redefined so that it applies to the same label
# In this case, it has to be ensured that the class
# that is overriding the relationship is a descendant
# of the already existing class.
model_from_registry = db._NODE_CLASS_REGISTRY[label_set]
if not issubclass(model, model_from_registry):
is_parent = issubclass(model_from_registry, model)
if is_direct_subclass(model, StructuredRel) and not is_parent:
raise RelationshipClassRedefined(
relation_type, db._NODE_CLASS_REGISTRY, model
)
``
` |
From the perspective of how we are using the code in the project, relationship labels do not always mean the same properties in the relationship. It's more like a general name, what this label means. If we have two sets of unrelated nodes, let's name them A, B, C, D:
While they are not intersecting with each other, there is no data conflict. Errors exist when you have conflicting labels, like:
In this case, we cannot understand the exact "Includes" relationship we assume. Neomodel should check only this intersection case when it is unclear how to resolve it. |
This works with
neomodel<4.0.8
, but with 4.0.8, install_labels raisesRelationshipClassRedefined
.The text was updated successfully, but these errors were encountered: