Skip to content

Commit

Permalink
Fix recursive definition error when computed property refers to diffe…
Browse files Browse the repository at this point in the history
…rent object's computed property. (#7431)

In the following schema
```
  type Foo {
    property a -> str;
    property b := .a;
  }

  type Bar {
    property a := .foo.b;
    link foo -> Foo;
  }
```

`Bar.a` refers to `Foo.b`, which refers to `Foo.a`. During path tracing, the `.a` was mistakenly taken to be `Bar.a` resulting in a faulty recursive definition error.
  • Loading branch information
dnwpark authored Jun 5, 2024
1 parent ecd957c commit e59a93f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion edb/edgeql/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,13 @@ def trace_Path(
# We haven't computed the target yet,
# so try computing it now.
ctx.visited.add(ptr)
ptr_target = trace(ptr.target_expr, ctx=ctx)

target_ctx = _fork_context(ctx)
target_ctx.path_prefix = sname
ptr_target = trace(
ptr.target_expr, ctx=target_ctx
)

if isinstance(ptr_target, (Type,
s_types.Type)):
tip = ptr.target = ptr_target
Expand Down
21 changes: 19 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4186,6 +4186,23 @@ def test_schema_get_migration_54(self):

self._assert_migration_consistency(schema)

def test_schema_get_migration_55(self):
# In Bar, `.foo.b` refers to `.a`. Ensure that when tracing, `.a` is
# correctly `Foo.a`, otherwise a recurisve definition is found.
schema = r'''
type Foo {
property a -> str;
property b := .a;
}
type Bar {
property a := .foo.b;
link foo -> Foo;
}
'''

self._assert_migration_consistency(schema)

def test_schema_get_migration_multi_module_01(self):
schema = r'''
# The two declared types declared are from different
Expand Down Expand Up @@ -6400,8 +6417,8 @@ def test_schema_migrations_equivalence_recursive_02(self):
with self.assertRaisesRegex(
errors.InvalidDefinitionError,
"definition dependency cycle between "
"property 'val' of object type 'default::Bar' and "
"property 'val' of object type 'default::Foo'"
"property 'val' of object type 'default::Foo' and "
"property 'val' of object type 'default::Bar'"
):
self._assert_migration_equivalence([r"""
type Foo {
Expand Down

0 comments on commit e59a93f

Please sign in to comment.