Skip to content

Commit

Permalink
Fix globals in nested modules (#474)
Browse files Browse the repository at this point in the history
Fixes #472.
  • Loading branch information
msullivan authored Feb 1, 2024
1 parent c916eef commit 004c87e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions edgedb/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def with_config(self, *args, **config):
)

def resolve(self, name: str) -> str:
parts = name.split("::")
parts = name.split("::", 1)
if len(parts) == 1:
return f"{self._module or 'default'}::{name}"
elif len(parts) == 2:
mod, name = parts
mod = self._aliases.get(mod, mod)
return f"{mod}::{name}"
else:
raise errors.InvalidArgumentError(f"Illegal name: {name}")
raise AssertionError('broken split')

def with_globals(self, *args, **globals_):
if len(args) > 1:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ async def test_globals_01(self):
CREATE GLOBAL def_glob -> str {
SET default := '!';
};
CREATE MODULE foo;
CREATE MODULE foo::bar;
CREATE GLOBAL foo::bar::baz -> str;
''')

async with db.with_globals(glob='test') as gdb:
Expand All @@ -61,6 +64,10 @@ async def test_globals_01(self):
x = await gdb.query_single('select global def_glob')
self.assertEqual(x, None)

async with db.with_globals({'foo::bar::baz': 'asdf'}) as gdb:
x = await gdb.query_single('select global foo::bar::baz')
self.assertEqual(x, 'asdf')

async def test_client_state_mismatch(self):
db = self.client
if db.is_proto_lt_1_0:
Expand Down

0 comments on commit 004c87e

Please sign in to comment.