prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ISE when LIMIT/OFFSET correlated with query
  ```
  sully> SELECT Object LIMIT len(<str>.id);
  ERROR: InternalServerError: argument of LIMIT must not contain variables
  ```
  
  ```
  sully> SELECT Object OFFSET len(<str>.id);
  ERROR: InternalServerError: argument of OFFSET must not contain variables
  ```
  
  Rejecting these is correct but we want a real error.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `edb/edgeql/compiler/clauses.py`
  Content:
  ```
  1 #
  2 # This source file is part of the EdgeDB open source project.
  3 #
  4 # Copyright 2008-present MagicStack Inc. and the EdgeDB authors.
  5 #
  6 # Licensed under the Apache License, Version 2.0 (the "License");
  7 # you may not use this file except in compliance with the License.
  8 # You may obtain a copy of the License at
  9 #
  10 #     http://www.apache.org/licenses/LICENSE-2.0
  11 #
  12 # Unless required by applicable law or agreed to in writing, software
  13 # distributed under the License is distributed on an "AS IS" BASIS,
  14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 # See the License for the specific language governing permissions and
  16 # limitations under the License.
  17 #
  18 
  19 
  20 """EdgeQL compiler functions to process shared clauses."""
  21 
  22 
  23 from __future__ import annotations
  24 
  25 from typing import *
  26 
  27 from edb.edgeql import ast as qlast
  28 from edb.ir import ast as irast
  29 
  30 from edb import errors
  31 
  32 from . import context
  33 from . import dispatch
  34 from . import inference
  35 from . import polyres
  36 from . import schemactx
  37 from . import setgen
  38 
  39 
  40 def compile_where_clause(
  41         ir_stmt: irast.FilteredStmt,
  42         where: Optional[qlast.Base], *,
  43         ctx: context.ContextLevel) -> None:
  44 
  45     if where is None:
  46         return
  47 
  48     with ctx.newscope(fenced=True) as subctx:
  49         subctx.path_scope.unnest_fence = True
  50         ir_expr = dispatch.compile(where, ctx=subctx)
  51         bool_t = ctx.env.get_track_schema_type('std::bool')
  52         ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx)
  53 
  54     ir_stmt.where = ir_set
  55 
  56 
  57 def compile_orderby_clause(
  58         sortexprs: Optional[Iterable[qlast.SortExpr]], *,
  59         ctx: context.ContextLevel) -> List[irast.SortExpr]:
  60 
  61     result: List[irast.SortExpr] = []
  62     if not sortexprs:
  63         return result
  64 
  65     with ctx.new() as subctx:
  66         for sortexpr in sortexprs:
  67             with subctx.newscope(fenced=True) as exprctx:
  68                 exprctx.path_scope.unnest_fence = True
  69                 ir_sortexpr = dispatch.compile(sortexpr.path, ctx=exprctx)
  70                 ir_sortexpr = setgen.scoped_set(
  71                     ir_sortexpr, force_reassign=True, ctx=exprctx)
  72                 ir_sortexpr.context = sortexpr.context
  73 
  74                 # Check that the sortexpr type is actually orderable
  75                 # with either '>' or '<' based on the DESC or ASC sort
  76                 # order.
  77                 env = exprctx.env
  78                 sort_type = inference.infer_type(ir_sortexpr, env)
  79                 # Postgres by default treats ASC as using '<' and DESC
  80                 # as using '>'. We should do the same.
  81                 if sortexpr.direction == qlast.SortDesc:
  82                     op_name = '>'
  83                 else:
  84                     op_name = '<'
  85                 opers = env.schema.get_operators(
  86                     op_name, module_aliases=exprctx.modaliases)
  87 
  88                 # Verify that a comparison operator is defined for 2
  89                 # sort_type expressions.
  90                 matched = polyres.find_callable(
  91                     opers,
  92                     args=[(sort_type, ir_sortexpr), (sort_type, ir_sortexpr)],
  93                     kwargs={},
  94                     ctx=exprctx)
  95                 if len(matched) != 1:
  96                     sort_type_name = schemactx.get_material_type(
  97                         sort_type, ctx=ctx).get_displayname(env.schema)
  98                     if len(matched) == 0:
  99                         raise errors.QueryError(
  100                             f'type {sort_type_name!r} cannot be used in '
  101                             f'ORDER BY clause because ordering is not '
  102                             f'defined for it',
  103                             context=sortexpr.context)
  104 
  105                     elif len(matched) > 1:
  106                         raise errors.QueryError(
  107                             f'type {sort_type_name!r} cannot be used in '
  108                             f'ORDER BY clause because ordering is '
  109                             f'ambiguous for it',
  110                             context=sortexpr.context)
  111 
  112             result.append(
  113                 irast.SortExpr(
  114                     expr=ir_sortexpr,
  115                     direction=sortexpr.direction,
  116                     nones_order=sortexpr.nones_order))
  117 
  118     return result
  119 
  120 
  121 def compile_limit_offset_clause(
  122         expr: Optional[qlast.Base], *,
  123         ctx: context.ContextLevel) -> Optional[irast.Set]:
  124     if expr is None:
  125         ir_set = None
  126     else:
  127         with ctx.newscope(fenced=True) as subctx:
  128             ir_expr = dispatch.compile(expr, ctx=subctx)
  129             int_t = ctx.env.get_track_schema_type('std::int64')
  130             ir_set = setgen.scoped_set(
  131                 ir_expr, force_reassign=True, typehint=int_t, ctx=subctx)
  132             ir_set.context = expr.context
  133 
  134     return ir_set
  135
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/edb/edgeql/compiler/clauses.py b/edb/edgeql/compiler/clauses.py
  --- a/edb/edgeql/compiler/clauses.py
  +++ b/edb/edgeql/compiler/clauses.py
  @@ -125,6 +125,10 @@
           ir_set = None
       else:
           with ctx.newscope(fenced=True) as subctx:
  +            # Clear out the partial_path_prefix, since we aren't in
  +            # the scope of the select subject
  +            subctx.partial_path_prefix = None
  +
               ir_expr = dispatch.compile(expr, ctx=subctx)
               int_t = ctx.env.get_track_schema_type('std::int64')
               ir_set = setgen.scoped_set(
  
verification_info: {"golden_diff": "diff --git a/edb/edgeql/compiler/clauses.py b/edb/edgeql/compiler/clauses.py\n--- a/edb/edgeql/compiler/clauses.py\n+++ b/edb/edgeql/compiler/clauses.py\n@@ -125,6 +125,10 @@\n         ir_set = None\n     else:\n         with ctx.newscope(fenced=True) as subctx:\n+            # Clear out the partial_path_prefix, since we aren't in\n+            # the scope of the select subject\n+            subctx.partial_path_prefix = None\n+\n             ir_expr = dispatch.compile(expr, ctx=subctx)\n             int_t = ctx.env.get_track_schema_type('std::int64')\n             ir_set = setgen.scoped_set(\n", "issue": "ISE when LIMIT/OFFSET correlated with query\n```\r\nsully> SELECT Object LIMIT len(<str>.id);\r\nERROR: InternalServerError: argument of LIMIT must not contain variables\r\n```\r\n\r\n```\r\nsully> SELECT Object OFFSET len(<str>.id);\r\nERROR: InternalServerError: argument of OFFSET must not contain variables\r\n```\r\n\r\nRejecting these is correct but we want a real error.\r\n\n", "before_files": [{"content": "#\n# This source file is part of the EdgeDB open source project.\n#\n# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n\n\"\"\"EdgeQL compiler functions to process shared clauses.\"\"\"\n\n\nfrom __future__ import annotations\n\nfrom typing import *\n\nfrom edb.edgeql import ast as qlast\nfrom edb.ir import ast as irast\n\nfrom edb import errors\n\nfrom . import context\nfrom . import dispatch\nfrom . import inference\nfrom . import polyres\nfrom . import schemactx\nfrom . import setgen\n\n\ndef compile_where_clause(\n        ir_stmt: irast.FilteredStmt,\n        where: Optional[qlast.Base], *,\n        ctx: context.ContextLevel) -> None:\n\n    if where is None:\n        return\n\n    with ctx.newscope(fenced=True) as subctx:\n        subctx.path_scope.unnest_fence = True\n        ir_expr = dispatch.compile(where, ctx=subctx)\n        bool_t = ctx.env.get_track_schema_type('std::bool')\n        ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx)\n\n    ir_stmt.where = ir_set\n\n\ndef compile_orderby_clause(\n        sortexprs: Optional[Iterable[qlast.SortExpr]], *,\n        ctx: context.ContextLevel) -> List[irast.SortExpr]:\n\n    result: List[irast.SortExpr] = []\n    if not sortexprs:\n        return result\n\n    with ctx.new() as subctx:\n        for sortexpr in sortexprs:\n            with subctx.newscope(fenced=True) as exprctx:\n                exprctx.path_scope.unnest_fence = True\n                ir_sortexpr = dispatch.compile(sortexpr.path, ctx=exprctx)\n                ir_sortexpr = setgen.scoped_set(\n                    ir_sortexpr, force_reassign=True, ctx=exprctx)\n                ir_sortexpr.context = sortexpr.context\n\n                # Check that the sortexpr type is actually orderable\n                # with either '>' or '<' based on the DESC or ASC sort\n                # order.\n                env = exprctx.env\n                sort_type = inference.infer_type(ir_sortexpr, env)\n                # Postgres by default treats ASC as using '<' and DESC\n                # as using '>'. We should do the same.\n                if sortexpr.direction == qlast.SortDesc:\n                    op_name = '>'\n                else:\n                    op_name = '<'\n                opers = env.schema.get_operators(\n                    op_name, module_aliases=exprctx.modaliases)\n\n                # Verify that a comparison operator is defined for 2\n                # sort_type expressions.\n                matched = polyres.find_callable(\n                    opers,\n                    args=[(sort_type, ir_sortexpr), (sort_type, ir_sortexpr)],\n                    kwargs={},\n                    ctx=exprctx)\n                if len(matched) != 1:\n                    sort_type_name = schemactx.get_material_type(\n                        sort_type, ctx=ctx).get_displayname(env.schema)\n                    if len(matched) == 0:\n                        raise errors.QueryError(\n                            f'type {sort_type_name!r} cannot be used in '\n                            f'ORDER BY clause because ordering is not '\n                            f'defined for it',\n                            context=sortexpr.context)\n\n                    elif len(matched) > 1:\n                        raise errors.QueryError(\n                            f'type {sort_type_name!r} cannot be used in '\n                            f'ORDER BY clause because ordering is '\n                            f'ambiguous for it',\n                            context=sortexpr.context)\n\n            result.append(\n                irast.SortExpr(\n                    expr=ir_sortexpr,\n                    direction=sortexpr.direction,\n                    nones_order=sortexpr.nones_order))\n\n    return result\n\n\ndef compile_limit_offset_clause(\n        expr: Optional[qlast.Base], *,\n        ctx: context.ContextLevel) -> Optional[irast.Set]:\n    if expr is None:\n        ir_set = None\n    else:\n        with ctx.newscope(fenced=True) as subctx:\n            ir_expr = dispatch.compile(expr, ctx=subctx)\n            int_t = ctx.env.get_track_schema_type('std::int64')\n            ir_set = setgen.scoped_set(\n                ir_expr, force_reassign=True, typehint=int_t, ctx=subctx)\n            ir_set.context = expr.context\n\n    return ir_set\n", "path": "edb/edgeql/compiler/clauses.py"}], "after_files": [{"content": "#\n# This source file is part of the EdgeDB open source project.\n#\n# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n\n\"\"\"EdgeQL compiler functions to process shared clauses.\"\"\"\n\n\nfrom __future__ import annotations\n\nfrom typing import *\n\nfrom edb.edgeql import ast as qlast\nfrom edb.ir import ast as irast\n\nfrom edb import errors\n\nfrom . import context\nfrom . import dispatch\nfrom . import inference\nfrom . import polyres\nfrom . import schemactx\nfrom . import setgen\n\n\ndef compile_where_clause(\n        ir_stmt: irast.FilteredStmt,\n        where: Optional[qlast.Base], *,\n        ctx: context.ContextLevel) -> None:\n\n    if where is None:\n        return\n\n    with ctx.newscope(fenced=True) as subctx:\n        subctx.path_scope.unnest_fence = True\n        ir_expr = dispatch.compile(where, ctx=subctx)\n        bool_t = ctx.env.get_track_schema_type('std::bool')\n        ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx)\n\n    ir_stmt.where = ir_set\n\n\ndef compile_orderby_clause(\n        sortexprs: Optional[Iterable[qlast.SortExpr]], *,\n        ctx: context.ContextLevel) -> List[irast.SortExpr]:\n\n    result: List[irast.SortExpr] = []\n    if not sortexprs:\n        return result\n\n    with ctx.new() as subctx:\n        for sortexpr in sortexprs:\n            with subctx.newscope(fenced=True) as exprctx:\n                exprctx.path_scope.unnest_fence = True\n                ir_sortexpr = dispatch.compile(sortexpr.path, ctx=exprctx)\n                ir_sortexpr = setgen.scoped_set(\n                    ir_sortexpr, force_reassign=True, ctx=exprctx)\n                ir_sortexpr.context = sortexpr.context\n\n                # Check that the sortexpr type is actually orderable\n                # with either '>' or '<' based on the DESC or ASC sort\n                # order.\n                env = exprctx.env\n                sort_type = inference.infer_type(ir_sortexpr, env)\n                # Postgres by default treats ASC as using '<' and DESC\n                # as using '>'. We should do the same.\n                if sortexpr.direction == qlast.SortDesc:\n                    op_name = '>'\n                else:\n                    op_name = '<'\n                opers = env.schema.get_operators(\n                    op_name, module_aliases=exprctx.modaliases)\n\n                # Verify that a comparison operator is defined for 2\n                # sort_type expressions.\n                matched = polyres.find_callable(\n                    opers,\n                    args=[(sort_type, ir_sortexpr), (sort_type, ir_sortexpr)],\n                    kwargs={},\n                    ctx=exprctx)\n                if len(matched) != 1:\n                    sort_type_name = schemactx.get_material_type(\n                        sort_type, ctx=ctx).get_displayname(env.schema)\n                    if len(matched) == 0:\n                        raise errors.QueryError(\n                            f'type {sort_type_name!r} cannot be used in '\n                            f'ORDER BY clause because ordering is not '\n                            f'defined for it',\n                            context=sortexpr.context)\n\n                    elif len(matched) > 1:\n                        raise errors.QueryError(\n                            f'type {sort_type_name!r} cannot be used in '\n                            f'ORDER BY clause because ordering is '\n                            f'ambiguous for it',\n                            context=sortexpr.context)\n\n            result.append(\n                irast.SortExpr(\n                    expr=ir_sortexpr,\n                    direction=sortexpr.direction,\n                    nones_order=sortexpr.nones_order))\n\n    return result\n\n\ndef compile_limit_offset_clause(\n        expr: Optional[qlast.Base], *,\n        ctx: context.ContextLevel) -> Optional[irast.Set]:\n    if expr is None:\n        ir_set = None\n    else:\n        with ctx.newscope(fenced=True) as subctx:\n            # Clear out the partial_path_prefix, since we aren't in\n            # the scope of the select subject\n            subctx.partial_path_prefix = None\n\n            ir_expr = dispatch.compile(expr, ctx=subctx)\n            int_t = ctx.env.get_track_schema_type('std::int64')\n            ir_set = setgen.scoped_set(\n                ir_expr, force_reassign=True, typehint=int_t, ctx=subctx)\n            ir_set.context = expr.context\n\n    return ir_set\n", "path": "edb/edgeql/compiler/clauses.py"}]}