Repository: edgedb/edgedb

Issue:
Unify disallow_dml with in_conditional
              Maybe make this an `Optional[str]` so we can say "UPDATE may not be done in a FILTER clause" or whatever

_Originally posted by @msullivan in https://github.com/edgedb/edgedb/pull/5130#discussion_r1127224316_
            


Discussion:

Resolving patch:
diff --git a/edb/edgeql/compiler/context.py b/edb/edgeql/compiler/context.py
--- a/edb/edgeql/compiler/context.py
+++ b/edb/edgeql/compiler/context.py
@@ -531,9 +531,6 @@ class ContextLevel(compiler.ContextLevel):
     compiling_update_shape: bool
     """Whether an UPDATE shape is currently being compiled."""
 
-    in_conditional: Optional[parsing.ParserContext]
-    """Whether currently in a conditional branch."""
-
     active_computeds: ordered.OrderedSet[s_pointers.Pointer]
     """A ordered set of currently compiling computeds"""
 
@@ -592,7 +589,6 @@ def __init__(
             self.empty_result_type_hint = None
             self.defining_view = None
             self.compiling_update_shape = False
-            self.in_conditional = None
             self.active_computeds = ordered.OrderedSet()
             self.recompiling_schema_alias = False
 
@@ -633,7 +629,6 @@ def __init__(
             self.empty_result_type_hint = prevlevel.empty_result_type_hint
             self.defining_view = prevlevel.defining_view
             self.compiling_update_shape = prevlevel.compiling_update_shape
-            self.in_conditional = prevlevel.in_conditional
             self.active_computeds = prevlevel.active_computeds
             self.recompiling_schema_alias = prevlevel.recompiling_schema_alias
 
diff --git a/edb/edgeql/compiler/polyres.py b/edb/edgeql/compiler/polyres.py
--- a/edb/edgeql/compiler/polyres.py
+++ b/edb/edgeql/compiler/polyres.py
@@ -568,7 +568,7 @@ def compile_arg(
     new = ctx.newscope(fenced=False) if optional else ctx.new()
     with new as argctx:
         if in_conditional:
-            argctx.in_conditional = arg_ql.context
+            argctx.disallow_dml = "inside conditional expressions"
 
         if optional:
             argctx.path_scope.mark_as_optional()
diff --git a/edb/edgeql/compiler/stmt.py b/edb/edgeql/compiler/stmt.py
--- a/edb/edgeql/compiler/stmt.py
+++ b/edb/edgeql/compiler/stmt.py
@@ -413,13 +413,6 @@ def compile_InsertQuery(
         expr: qlast.InsertQuery, *,
         ctx: context.ContextLevel) -> irast.Set:
 
-    if ctx.in_conditional is not None:
-        raise errors.QueryError(
-            'INSERT statements cannot be used inside conditional '
-            'expressions',
-            context=expr.context,
-        )
-
     if ctx.disallow_dml:
         raise errors.QueryError(
             f'INSERT statements cannot be used {ctx.disallow_dml}',
@@ -563,12 +556,6 @@ def _get_dunder_type_ptrref(ctx: context.ContextLevel) -> irast.PointerRef:
 def compile_UpdateQuery(
         expr: qlast.UpdateQuery, *, ctx: context.ContextLevel) -> irast.Set:
 
-    if ctx.in_conditional is not None:
-        raise errors.QueryError(
-            'UPDATE statements cannot be used inside conditional expressions',
-            context=expr.context,
-        )
-
     if ctx.disallow_dml:
         raise errors.QueryError(
             f'UPDATE statements cannot be used {ctx.disallow_dml}',
@@ -669,12 +656,6 @@ def compile_UpdateQuery(
 def compile_DeleteQuery(
         expr: qlast.DeleteQuery, *, ctx: context.ContextLevel) -> irast.Set:
 
-    if ctx.in_conditional is not None:
-        raise errors.QueryError(
-            'DELETE statements cannot be used inside conditional expressions',
-            context=expr.context,
-        )
-
     if ctx.disallow_dml:
         raise errors.QueryError(
             f'DELETE statements cannot be used {ctx.disallow_dml}',


Test patch: