Repository: edgedb/edgedb

Issue:
InternalServerError: column "f68496a2-eca2-11ec-b62e-d34bce7c0a12" is of type uuid but expression is of type record
<!-- Please search existing issues to avoid creating duplicates. -->
- EdgeDB Version: 1.4
- OS Version: Windows 10.0.19044

edgedb migrate
Connecting to an EdgeDB instance at localhost:10701...
edgedb error: InternalServerError: column "f68496a2-eca2-11ec-b62e-d34bce7c0a12" is of type uuid but expression is of type record
  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:
      edb.errors.InternalServerError: column "f68496a2-eca2-11ec-b62e-d34bce7c0a12" is of type uuid but expression is of type record

[Project stucture](https://drive.google.com/file/d/1gecCtXrjQjRKPfD8poaxd22g9FNz4nnz/view?usp=sharing)


Discussion:
The culprit as to why things are going wrong is this expression for populating the newly created `logo` field:
```
          SELECT
              default::Logo {
                  url := 'some_url'
              }
          LIMIT
              1
```
We generate bogus code for it because of the presence of the shape, but the shape doesn't accomplish anything even if we didn't mess up

I think it should produce an error

Resolving patch:
diff --git a/edb/schema/pointers.py b/edb/schema/pointers.py
--- a/edb/schema/pointers.py
+++ b/edb/schema/pointers.py
@@ -1589,6 +1589,11 @@ def validate_object(
             assert ptr_target is not None
 
             source_context = self.get_attribute_source_context('default')
+            if default_type.is_view(default_expr.irast.schema):
+                raise errors.SchemaDefinitionError(
+                    f'default expression may not include a shape',
+                    context=source_context,
+                )
             if not default_type.assignment_castable_to(ptr_target, schema):
                 raise errors.SchemaDefinitionError(
                     f'default expression is of invalid type: '
@@ -2213,6 +2218,12 @@ def _alter_begin(
                         hint='You might need to add an explicit cast.',
                         context=self.source_context,
                     )
+                if using_type.is_view(self.cast_expr.schema):
+                    raise errors.SchemaError(
+                        f'result of USING clause for the alteration of '
+                        f'{vn} may not include a shape',
+                        context=self.source_context,
+                    )
 
             schema = self._propagate_if_expr_refs(
                 schema,
@@ -2388,6 +2399,12 @@ def _alter_begin(
                         hint='You might need to add an explicit cast.',
                         context=self.source_context,
                     )
+                if using_type.is_view(self.conv_expr.schema):
+                    raise errors.SchemaError(
+                        f'result of USING clause for the alteration of '
+                        f'{vn} may not include a shape',
+                        context=self.source_context,
+                    )
 
             schema = self._propagate_if_expr_refs(schema, context, action=desc)
             self._propagate_ref_field_alter_in_inheritance(
@@ -2596,6 +2613,12 @@ def _alter_begin(
                         hint='You might need to add an explicit cast.',
                         context=self.source_context,
                     )
+                if using_type.is_view(self.fill_expr.schema):
+                    raise errors.SchemaError(
+                        f'result of USING clause for the alteration of '
+                        f'{vn} may not include a shape',
+                        context=self.source_context,
+                    )
 
             schema = self._propagate_if_expr_refs(
                 schema,


Test patch:
diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py
--- a/tests/test_edgeql_ddl.py
+++ b/tests/test_edgeql_ddl.py
@@ -14360,6 +14360,35 @@ async def test_edgeql_no_type_intro_in_default(self):
             insert Project;
         """)
 
+    async def test_edgeql_ddl_no_shapes_in_using(self):
+        await self.con.execute(r"""
+            create type Foo;
+            create type Bar extending Foo;
+            create type Baz {
+                create multi link foo -> Foo;
+            };
+        """)
+
+        q = 'select Bar { x := "oops" } limit 1'
+        alters = [
+            f'set required using ({q})',
+            f'set single using ({q})',
+            f'set default := ({q})',
+            f'set type Bar using ({q})',
+        ]
+
+        for alter in alters:
+            async with self.assertRaisesRegexTx(
+                    (edgedb.SchemaError, edgedb.SchemaDefinitionError),
+                    r"may not include a shape"):
+                await self.con.execute(fr"""
+                    alter type Baz {{
+                        alter link foo {{
+                            {alter}
+                        }}
+                     }};
+                """)
+
     async def test_edgeql_ddl_uuid_array_01(self):
         await self.con.execute(r"""
             create type Foo {