Skip to content
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

Fix globals in nested modules #474

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading