# Buggy code
def get_path_output(
    rel: pgast.BaseRelation,
    path_id: irast.PathId,
    *,
    aspect: str,
    allow_nullable: bool = True,
    ptr_info: Optional[pg_types.PointerStorageInfo] = None,
    env: context.Environment,
) -> pgast.OutputVar:
    view_path_id_map = getattr(rel, "view_path_id_map", None)
    if view_path_id_map:
        path_id = map_path_id(path_id, view_path_id_map)

    return _get_path_output(
        rel,
        path_id=path_id,
        aspect=aspect,
        ptr_info=ptr_info,
        allow_nullable=allow_nullable,
        env=env,
    )


# Traceback (edb.errors.InternalServerError)
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/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-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1816, in compile_eql_tokens_in_tx
return self._compile(ctx=ctx, tokens=eql_tokens)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1429, in _compile
comp: dbstate.BaseQuery = self._compile_dispatch_ql(ctx, stmt)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1352, in _compile_dispatch_ql
return self._compile_ql_migration(ctx, ql)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1047, in _compile_ql_migration
ddl_query = self._compile_and_apply_ddl_stmt(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 752, in _compile_and_apply_ddl_stmt
block, new_types = self._process_delta(ctx, delta)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 412, in _process_delta
schema = delta.apply(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 4027, in apply
schema = sd.DeltaRoot.apply(self, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 1094, in apply
schema = objop.apply(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 194, in apply
schema = self.__class__.get_adaptee().apply(self, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 2037, in apply
schema = self._create_innards(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 2005, in _create_innards
schema = op.apply(schema, context=context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 595, in apply
schema, op = self.make_op(self.scls, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 575, in make_op
dbf = self.compile_edgeql_function(func, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 546, in compile_edgeql_function
sql_text, _ = compiler.compile_ir_to_sql(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/compiler/__init__.py", line 105, in compile_ir_to_sql
qtree = compile_ir_to_sql_tree(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/compiler/__init__.py", line 90, in compile_ir_to_sql_tree
raise errors.InternalServerError(*args) from e
edb.errors.InternalServerError: list index out of range

# Fixed code
def get_path_output(
    rel: pgast.BaseRelation,
    path_id: irast.PathId,
    *,
    aspect: str,
    allow_nullable: bool = True,
    ptr_info: Optional[pg_types.PointerStorageInfo] = None,
    env: context.Environment,
) -> pgast.OutputVar:
    if isinstance(rel, pgast.Query):
        path_id = map_path_id(path_id, rel.view_path_id_map)

    return _get_path_output(
        rel,
        path_id=path_id,
        aspect=aspect,
        ptr_info=ptr_info,
        allow_nullable=allow_nullable,
        env=env,
    )