Skip to content

Commit

Permalink
make converting type to aliases actaully work
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Mar 4, 2024
1 parent 7e839d3 commit c10fd5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
13 changes: 11 additions & 2 deletions edb/schema/expraliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 6 additions & 7 deletions tests/test_edgeql_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c10fd5b

Please sign in to comment.