From 07b9b53fb3da93a099b90d70d49820f63f860051 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Thu, 1 Feb 2024 11:30:39 -0800 Subject: [PATCH] Fix globals in nested modules Fixes #472. --- edgedb/options.py | 4 ++-- tests/test_globals.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/edgedb/options.py b/edgedb/options.py index 714168ab..f325033c 100644 --- a/edgedb/options.py +++ b/edgedb/options.py @@ -182,7 +182,7 @@ 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: @@ -190,7 +190,7 @@ def resolve(self, name: str) -> str: 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: diff --git a/tests/test_globals.py b/tests/test_globals.py index f8badbd4..1369828c 100644 --- a/tests/test_globals.py +++ b/tests/test_globals.py @@ -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: @@ -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: