From c10fd5bf1f5246c15a473c9860012508294730f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 4 Mar 2024 15:34:03 +0100 Subject: [PATCH] make converting type to aliases actaully work --- edb/schema/expraliases.py | 13 +++++++++++-- tests/test_edgeql_ddl.py | 13 ++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/edb/schema/expraliases.py b/edb/schema/expraliases.py index a4e781449f7..4a913b20d09 100644 --- a/edb/schema/expraliases.py +++ b/edb/schema/expraliases.py @@ -563,8 +563,17 @@ def _create_alias_types( if op.classname == classname: type_cmd = op break - assert type_cmd - + if not type_cmd: + # create type command does not exist, because the type already exists + # (this happens when converting a type into an alias) + ty = schema.get(classname, type=s_types.Type) + assert ty + type_cmd = ty.init_delta_command(schema, sd.AlterObject) + type_cmd.canonical = True + type_cmd.set_attribute_value('alias_is_persistent', True) + type_cmd.set_attribute_value('expr_type', s_types.ExprType.Select) + type_cmd.set_attribute_value('from_alias', True) + type_cmd.set_attribute_value('from_global', is_global) type_cmd.set_attribute_value('expr', expr) result = sd.CommandGroup() diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py index 1ae81a9da9c..65dd77ebb0b 100644 --- a/tests/test_edgeql_ddl.py +++ b/tests/test_edgeql_ddl.py @@ -9878,13 +9878,12 @@ async def test_edgeql_ddl_alias_12(self): await self.con.execute(r""" create alias X := 2; """) - async with self.assertRaisesRegexTx( - edgedb.SchemaError, - "type 'default::Y' already exists" - ): - await self.con.execute(r""" - create alias Y := 2; - """) + + # this is allowed: it converts the type into an alias + await self.con.execute(r""" + create alias Y := 2; + """) + async with self.assertRaisesRegexTx( edgedb.SchemaError, "global 'default::Z' already exists"