Skip to content

Commit

Permalink
Fixed bug where primary keys were not correctly parsed if the primary…
Browse files Browse the repository at this point in the history
… attribute was wrapped
  • Loading branch information
jkminder committed Jun 10, 2022
1 parent a382824 commit eb633ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rel2graph/core/schema_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from collections import Counter
import re
import logging
from numpy import extract
from ply import lex, yacc

from .factories.registrar import get_factory
Expand Down Expand Up @@ -136,6 +137,13 @@ def p_entity(self, p):
# clear identifier list
self._identifiers = []

@staticmethod
def _extract_key_from_attribute(attribute):
if attribute[0] == "AttributeFactory":
return attribute[1][0]
else:
return SchemaConfigParser._extract_key_from_attribute(attribute[1][0])

@staticmethod
def _inject_graphelement_args(instructions, attributes, identifier):
"""
Expand All @@ -157,7 +165,7 @@ def _inject_graphelement_args(instructions, attributes, identifier):
if primary_key is not None:
raise SchemaConfigException(
f"Setting two or more primary keys for one graphelement is not allowed. Conflict: '{primary_key}' <-> '{attribute[1][0]}'")
primary_key = attribute[1][0]
primary_key = SchemaConfigParser._extract_key_from_attribute(attribute)
instructions[1].insert(0, raw_attributes)
instructions[1].extend([primary_key, identifier])
else:
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/core/resources/primary_keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ ENTITY("entity"):
NODE("pk") c:
+ pk = entity.pk
- attr = "someattr"
NODE("pk") e:
+ pk = WRAPPER(WRAPPER(entity.pk))
NODE("pk") d:
+ pk = WRAPPER(entity.pk)
RELATION(a, "noattr", c):
RELATION(a, "nopk", c):
- attr = "someattr"
RELATION(a, "pk", c):
+ pk = entity.pk
- attr = "someattr"
RELATION(a, "pk", c):
+ pk = WRAPPER(entity.pk)
RELATION(a, "pk", c):
+ pk = WRAPPER(WRAPPER(entity.pk))

2 changes: 2 additions & 0 deletions tests/unit/core/test_schema_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from rel2graph.core.schema_compiler import compile_schema, SchemaConfigParser, _precompile
from rel2graph import register_attribute_preprocessor, SchemaConfigException



######## TESTS PRECOMPILER ##########

def test_precompile_commentremoval():
Expand Down

0 comments on commit eb633ef

Please sign in to comment.