# Buggy code
def canonicalize_attributes(
    self,
    schema: s_schema.Schema,
    context: sd.CommandContext,
) -> s_schema.Schema:
    schema = super().canonicalize_attributes(schema, context)
    target_ref = self.get_local_attribute_value("target")
    inf_target_ref: Optional[s_types.TypeShell]

    # When cardinality/required is altered, we need to force a
    # reconsideration of expr if it exists in order to check
    # it against the new specifier or compute them on a
    # RESET. This is kind of unfortunate.
    if (
        isinstance(self, sd.AlterObject)
        and (
            self.has_attribute_value("cardinality")
            or self.has_attribute_value("required")
        )
        and not self.has_attribute_value("expr")
        and (expr := self.scls.get_expr(schema)) is not None
    ):
        self.set_attribute_value("expr", s_expr.Expression.not_compiled(expr))

    if isinstance(target_ref, ComputableRef):
        schema, inf_target_ref, base = self._parse_computable(
            target_ref.expr, schema, context
        )
    elif (expr := self.get_local_attribute_value("expr")) is not None:
        schema, inf_target_ref, base = self._parse_computable(
            expr.qlast, schema, context
        )
    else:
        inf_target_ref = None
        base = None

    if base is not None:
        self.set_attribute_value(
            "bases",
            so.ObjectList.create(schema, [base]),
        )

        self.set_attribute_value("is_derived", True)

        if context.declarative:
            self.set_attribute_value("declared_overloaded", True)

    if inf_target_ref is not None:
        srcctx = self.get_attribute_source_context("target")
        self.set_attribute_value(
            "target",
            inf_target_ref,
            source_context=srcctx,
        )

    schema = s_types.materialize_type_in_attribute(schema, context, self, "target")

    expr = self.get_local_attribute_value("expr")
    if expr is not None:
        # There is an expression, therefore it is a computable.
        self.set_attribute_value("computable", True)

    return schema


# Traceback (AttributeError)
ERROR: InternalServerError: 'UnionType' object has no attribute 'get_name'
Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
Server traceback:
Traceback (most recent call last):
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/procpool/worker.py", line 75, in worker
res = await meth(*args)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1808, in compile_eql_tokens
return self._compile(ctx=ctx, tokens=eql_tokens)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1442, in _compile
comp: dbstate.BaseQuery = self._compile_dispatch_ql(ctx, stmt)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1365, in _compile_dispatch_ql
return self._compile_ql_migration(ctx, ql)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 794, in _compile_ql_migration
target_schema = s_ddl.apply_sdl(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/ddl.py", line 371, in apply_sdl
ddl_stmts = s_decl.sdl_to_ddl(current_schema, documents)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/declarative.py", line 230, in sdl_to_ddl
trace_dependencies(decl_ast, ctx=ctx)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/functools.py", line 875, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/declarative.py", line 499, in trace_default
_register_item(node, ctx=ctx)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/declarative.py", line 623, in _register_item
trace_dependencies(cmd, ctx=ctx)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/functools.py", line 875, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/declarative.py", line 443, in trace_ConcretePointer
_register_item(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/declarative.py", line 638, in _register_item
tdeps = qltracer.trace_refs(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/tracer.py", line 162, in trace_refs
trace(qltree, ctx=ctx)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/functools.py", line 875, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/edgeql/tracer.py", line 653, in trace_Select
ctx.path_prefix = tip.get_name(ctx.schema)
AttributeError: 'UnionType' object has no attribute 'get_name'

# Fixed code
def canonicalize_attributes(
    self,
    schema: s_schema.Schema,
    context: sd.CommandContext,
) -> s_schema.Schema:
    schema = super().canonicalize_attributes(schema, context)
    target_ref = self.get_local_attribute_value("target")
    inf_target_ref: Optional[s_types.TypeShell]

    # When cardinality/required is altered, we need to force a
    # reconsideration of expr if it exists in order to check
    # it against the new specifier or compute them on a
    # RESET. This is kind of unfortunate.
    if (
        isinstance(self, sd.AlterObject)
        and (
            self.has_attribute_value("cardinality")
            or self.has_attribute_value("required")
        )
        and not self.has_attribute_value("expr")
        and (expr := self.scls.get_expr(schema)) is not None
    ):
        self.set_attribute_value("expr", s_expr.Expression.not_compiled(expr))

    if isinstance(target_ref, ComputableRef):
        schema, inf_target_ref, base = self._parse_computable(
            target_ref.expr, schema, context
        )
    elif (expr := self.get_local_attribute_value("expr")) is not None:
        schema, inf_target_ref, base = self._parse_computable(
            expr.qlast, schema, context
        )
    else:
        inf_target_ref = None
        base = None

    if base is not None:
        self.set_attribute_value(
            "bases",
            so.ObjectList.create(schema, [base]),
        )

        self.set_attribute_value("is_derived", True)

        if context.declarative:
            self.set_attribute_value("declared_overloaded", True)

    if inf_target_ref is not None:
        srcctx = self.get_attribute_source_context("target")
        self.set_attribute_value(
            "target",
            inf_target_ref,
            source_context=srcctx,
            computed=True,
        )

    schema = s_types.materialize_type_in_attribute(schema, context, self, "target")

    expr = self.get_local_attribute_value("expr")
    if expr is not None:
        # There is an expression, therefore it is a computable.
        self.set_attribute_value("computable", True)

    return schema