internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: edgedb/edgedb

Issue:
Migrations with scalar globals don't work if scalar type declared further below
- EdgeDB Version: 3.0-rc.5+4b31238
- EdgeDB CLI Version: 3.1.3+9fdca62
- OS Version: Windows 11

There seems to be an edge case where order matters in a migration: when a global scalar is declared and nothing else is using the scalar type.

Steps to Reproduce:

1. Start with a clean slate and try to do a migration with `edgedb migration create`.

This schema works: a scalar type that is declared after the global using it, but not required.

```
module default {
  scalar type TwoThings extending enum<One, Two>;
  global two_things: TwoThings;
}
```

Move the global type above though and it fails:

```
module default {
  global two_things: TwoThings;
  scalar type TwoThings extending enum<One, Two>;
}
```

Error:

```
Error:

error: type 'default::TwoThings' does not exist
  ┌─ c:\rust\anything\dbschema\default.esdl:2:31
  │
2 │   required global two_things: TwoThings {
  │                               ^^^^^^^^^ error

edgedb error: cannot proceed until .esdl files are fixed
```

Interestingly, if another type is declared before the global that holds the scalar then the global does pick it up and the migration works even though the scalar type isn't declared until after the global.

```
module default {
  type HoldsTwoThings {
    value: TwoThings;
  }
  global two_things: TwoThings;
  scalar type TwoThings extending enum<One, Two>;
}
```


Discussion:

Resolving patch:
diff --git a/edb/edgeql/declarative.py b/edb/edgeql/declarative.py
--- a/edb/edgeql/declarative.py
+++ b/edb/edgeql/declarative.py
@@ -996,12 +996,14 @@ def trace_Global(
     *,
     ctx: DepTraceContext,
 ) -> None:
-    hard_dep_exprs = []
+    deps: List[Dependency] = []
 
-    if isinstance(node.target, qlast.Expr):
-        hard_dep_exprs.append(ExprDependency(expr=node.target))
+    if isinstance(node.target, qlast.TypeExpr):
+        deps.append(TypeDependency(texpr=node.target))
+    elif isinstance(node.target, qlast.Expr):
+        deps.append(ExprDependency(expr=node.target))
 
-    _register_item(node, hard_dep_exprs=hard_dep_exprs, ctx=ctx)
+    _register_item(node, hard_dep_exprs=deps, ctx=ctx)
 
 
 @trace_dependencies.register


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -850,6 +850,12 @@ def test_schema_func_optional_variadic_01(self):
                 using (assert_exists(bar));
         """
 
+    def test_schema_global_01(self):
+        """
+          global two_things: TwoThings;
+          scalar type TwoThings extending enum<One, Two>;
+       """
+
     def test_schema_hard_sorting_01(self):
         # This is hard to sort properly because we don't understand the types.
         # From #4683.
Repository: edgedb/edgedb

Issue:
JWT authentication fails when databases (`edb.d`) specified
- EdgeDB Version: 3.2+bb17a05

```python
>>> from edb.common import secretkey
>>> secretkey.generate_secret_key(key, databases=['edgedb'])
'edbt1_ey...'
```

```
edgedb> CONFIGURE INSTANCE INSERT Auth {
.......     priority := 0,
.......     method := (INSERT JWT {
.......         transports := cfg::ConnectionTransport.TCP
.......     }),
....... };
OK: CONFIGURE INSTANCE
```

```
$ edgedb --host localhost --port 10721 --user edgedb --tls-security insecure --secret-key edbt1_ey...
edgedb error: AuthenticationError: authentication failed: secret key does not authorize access to database "None"
  Server traceback:
      Traceback (most recent call last):
        File "edb/server/protocol/frontend.pyx", line 294, in edb.server.protocol.frontend.FrontendConnection.main
        File "edb/server/protocol/binary.pyx", line 1022, in authenticate
        File "edb/server/protocol/binary.pyx", line 282, in auth
        File "edb/server/protocol/frontend.pyx", line 536, in _authenticate
        File "edb/server/protocol/binary.pyx", line 468, in edb.server.protocol.binary.EdgeConnection._auth_jwt
        File "edb/server/protocol/binary.pyx", line 504, in edb.server.protocol.binary.EdgeConnection._check_jwt_authz
      edb.errors.AuthenticationError: authentication failed: secret key does not authorize access to database "None"
```

The test `test_server_auth_jwt_1()` is mistakingly skipped in CI.

Refs #5744


Discussion:

Resolving patch:
diff --git a/edb/server/cluster.py b/edb/server/cluster.py
--- a/edb/server/cluster.py
+++ b/edb/server/cluster.py
@@ -498,6 +498,12 @@ def __init__(
 class RunningCluster(BaseCluster):
     def __init__(self, **conn_args: Any) -> None:
         self.conn_args = conn_args
+        if path := os.environ.get("EDGEDB_SERVER_JWS_KEY_FILE"):
+            try:
+                jws_key = secretkey.load_secret_key(pathlib.Path(path))
+            except secretkey.SecretKeyReadError as e:
+                raise ClusterError(e.args[0]) from e
+            self.get_jws_key = lambda: jws_key
 
     def is_managed(self) -> bool:
         return False


Test patch:
diff --git a/tests/test_server_auth.py b/tests/test_server_auth.py
--- a/tests/test_server_auth.py
+++ b/tests/test_server_auth.py
@@ -29,7 +29,6 @@
 
 from edb.common import secretkey
 from edb.schema import defines as s_def
-from edb.server import cluster as edb_cluster
 from edb.testbase import server as tb
 
 
@@ -241,7 +240,7 @@ async def test_server_auth_jwt_1(self):
         if not self.has_create_role:
             self.skipTest("create role is not supported by the backend")
 
-        if not isinstance(self.cluster, edb_cluster.Cluster):
+        if not hasattr(self.cluster, "get_jws_key"):
             raise unittest.SkipTest("test not supported on remote cluster")
 
         jwk = self.cluster.get_jws_key()
Repository: edgedb/edgedb

Issue:
assert_exists and similar don't work right in conv expressions
```
edgedb> start transaction;
....... alter type X {
.......     create required property foo -> str {
.......         set required using (assert_exists((select '' filter true)));
.......     };
....... };
OK: START TRANSACTION
edgedb error: MissingRequiredError: missing value for required property 'foo' of object type 'default::X'
```



Discussion:

Resolving patch:
diff --git a/edb/pgsql/delta.py b/edb/pgsql/delta.py
--- a/edb/pgsql/delta.py
+++ b/edb/pgsql/delta.py
@@ -4864,7 +4864,7 @@ def _compile_conversion_expr(
         root_uid = -1
         iter_uid = -2
         body_uid = -3
-        # scope tree wrapping is roughy equivalent to:
+        # scope tree wrapping is roughly equivalent to:
         # "(std::obj) uid:-1": {
         #   "BRANCH uid:-2",
         #   "FENCE uid:-3": { ... compiled scope children ... }
@@ -4876,7 +4876,9 @@ def _compile_conversion_expr(
             unique_id=body_uid,
             fenced=True
         )
-        for child in ir.scope_tree.children:
+        # Need to make a copy of the children list because
+        # attach_child removes the node from the parent list.
+        for child in list(ir.scope_tree.children):
             scope_body.attach_child(child)
 
         scope_root = irast.ScopeTreeNode(


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
@@ -3243,6 +3243,23 @@ async def test_edgeql_ddl_ptr_set_required_01(self):
                 ],
             )
 
+        # Something simple but forcing it to use assert_exists
+        async with self._run_and_rollback():
+            await self.con.execute("""
+                ALTER TYPE Foo ALTER PROPERTY p {
+                    SET REQUIRED USING (
+                        assert_exists((select '3' filter true)))
+                }
+            """)
+
+            await self.assert_query_result(
+                'SELECT Foo { p } ORDER BY .p',
+                [
+                    {'p': '1'},
+                    {'p': '3'},
+                ],
+            )
+
         # A reference to another property of the same host type.
         async with self._run_and_rollback():
             await self.con.execute("""
Repository: edgedb/edgedb

Issue:
Computed backlink in query results in `edgedb error: ProtocolEncodingError: object data size does not match its shape`
<!-- Please search existing issues to avoid creating duplicates. -->

<!--
For the EdgeDB Version: run `edgedb query 'select sys::get_version_as_str()'` from your project directory (or run `select sys::get_version_as_str();` in the EdgeDB interactive shell).
For the EdgeDB CLI Version: Run `edgedb --version` from anywhere
-->

- EdgeDB Version: 3.2+44862ed
- EdgeDB CLI Version: 3.4.0+4d95a2c
- OS Version: macOS 13.4.1

Steps to Reproduce:

1. Run this query against the schema below:
```
select Person {name, descendants := .<ancestors[is Person]};
```

Schema:
```
module default {
  type Person {
    required name: str;
    multi ancestors: Person;
  }
}
```


Discussion:
```
select schema::Type {name, refs := .<target[is schema::Pointer]};
```
hits it with an empty schema

The issue seems to be that the injected typename isn't getting reported in the type descriptor sent to the client.

This is a 3.x regression, it worked in 2.16. Probably introduced by the big refactors to sertypes.py
Oh, actually, looks like it was introduced by some of the backlink link properties stuff

Resolving patch:
diff --git a/edb/edgeql/compiler/schemactx.py b/edb/edgeql/compiler/schemactx.py
--- a/edb/edgeql/compiler/schemactx.py
+++ b/edb/edgeql/compiler/schemactx.py
@@ -328,9 +328,6 @@ def derive_ptr(
     if derive_backlink:
         attrs = attrs.copy() if attrs else {}
         attrs['computed_backlink'] = ptr
-        ntarget = ptr.get_source(ctx.env.schema)
-        assert isinstance(ntarget, s_types.Type)
-        target = ntarget
         ptr = ctx.env.schema.get('std::link', type=s_pointers.Pointer)
 
     ctx.env.schema, derived = ptr.derive_ref(


Test patch:
diff --git a/tests/test_edgeql_select.py b/tests/test_edgeql_select.py
--- a/tests/test_edgeql_select.py
+++ b/tests/test_edgeql_select.py
@@ -8223,3 +8223,12 @@ async def test_edgeql_type_pointer_inlining_02(self):
             ''',
             __typenames__=True
         )
+
+    async def test_edgeql_type_pointer_backlink_01(self):
+        # Type injection on bare backlinks was broken in 3.x (#5930)
+        await self.con._fetchall(
+            r'''
+            select schema::Type {name, refs := .<target[is schema::Pointer]};
+            ''',
+            __typenames__=True
+        )
Repository: edgedb/edgedb

Issue:
UPDATE rewrites of tuple properties don't work in json output mode
```
edgedb> \set output-format json
edgedb> create type X {
.......     create property tup -> tuple<int64, str> {
.......         create rewrite insert, update using ((1, '2'));
.......     };
....... };
OK: DROP TYPE
OK: CREATE TYPE
edgedb> insert X;
[{"id": "6369179a-695c-11ee-92ac-93480ecf45fe"}]
edgedb> update X set {};
edgedb error: InternalServerError: column "62e9e4fd-695c-11ee-be22-1d8f24c4f4a6" is of type edgedbpub."62e9dea5-695c-11ee-b7d1-7bdbae1f81d6_t" but expression is of type json
  Server traceback:
      edb.errors.InternalServerError: column "62e9e4fd-695c-11ee-be22-1d8f24c4f4a6" is of type edgedbpub."62e9dea5-695c-11ee-b7d1-7bdbae1f81d6_t" but expression is of type json
edgedb> \set output-format default
edgedb> update X set {};
{default::X {id: 6369179a-695c-11ee-92ac-93480ecf45fe}}
```

My guess is that something in the rewrite update path is using the wrong functions from `output`?


Discussion:

Resolving patch:
diff --git a/edb/pgsql/compiler/dml.py b/edb/pgsql/compiler/dml.py
--- a/edb/pgsql/compiler/dml.py
+++ b/edb/pgsql/compiler/dml.py
@@ -1984,6 +1984,7 @@ def process_update_shape(
             and updvalue is not None
         ):
             with ctx.newscope() as scopectx:
+                scopectx.expr_exposed = False
                 val: pgast.BaseExpr
 
                 if irtyputils.is_tuple(element.typeref):


Test patch:
diff --git a/tests/test_edgeql_rewrites.py b/tests/test_edgeql_rewrites.py
--- a/tests/test_edgeql_rewrites.py
+++ b/tests/test_edgeql_rewrites.py
@@ -953,3 +953,28 @@ async def test_edgeql_rewrites_23(self):
             'select Person { first_name }',
             [{'first_name': 'updated'}],
         )
+
+    async def test_edgeql_rewrites_24(self):
+        await self.con.execute(
+            '''
+            create type X {
+                create property tup -> tuple<int64, str> {
+                    create rewrite insert, update using ((1, '2'));
+                };
+            };
+            insert X;
+            '''
+        )
+        await self.assert_query_result(
+            'select X { tup }',
+            [{'tup': (1, '2')}],
+        )
+        await self.con.execute(
+            '''
+            update X set {};
+            '''
+        )
+        await self.assert_query_result(
+            'select X { tup }',
+            [{'tup': (1, '2')}],
+        )
Repository: edgedb/edgedb

Issue:
ISE when dumping database with auth ui enabled
- EdgeDB Version: 5.0-dev.7995+ea1ed23
- EdgeDB CLI Version: 3.5.0+907ff37
- OS Version: WSL Ubuntu 22.04

Steps to Reproduce:

1. Enable auth ext and auth ui:
```
edgedb> create extension pgcrypto;
OK: CREATE EXTENSION
edgedb> create extension auth;
OK: CREATE EXTENSION
edgedb> configure current database insert ext::auth::UIConfig {
.......   redirect_to := 'http://example.edgedb.com'
....... };
OK: CONFIGURE DATABASE
```
2. Try to dump the instance:
```bash
$ edgedb -I temp dump --all --format=dir dump
edgedb error: InternalServerError: error receiving dump header: TypeError: 'CompositeConfigType' object is not iterable
  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 "/home/james/.local/share/edgedb/portable/5.0-dev.7995/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 1044, in describe_database_dump
          user_config_ddl = config.to_edgeql(
                            ^^^^^^^^^^^^^^^^^
        File "/home/james/.local/share/edgedb/portable/5.0-dev.7995/lib/python3.11/site-packages/edb/server/config/ops.py", line 462, in to_edgeql
          for x in value.value:
      TypeError: 'CompositeConfigType' object is not iterable
```



Discussion:

Resolving patch:
diff --git a/edb/server/config/ops.py b/edb/server/config/ops.py
--- a/edb/server/config/ops.py
+++ b/edb/server/config/ops.py
@@ -459,7 +459,8 @@ def to_edgeql(
         if setting.secret and not with_secrets:
             continue
         if isinstance(setting.type, types.ConfigTypeSpec):
-            for x in value.value:
+            values = value.value if setting.set_of else [value.value]
+            for x in values:
                 # We look at the specific type of the object because
                 # a subtype could have a secret that the parent doesn't.
                 if x._tspec.has_secret and not with_secrets:


Test patch:
diff --git a/tests/schemas/dump_v4_setup.edgeql b/tests/schemas/dump_v4_setup.edgeql
--- a/tests/schemas/dump_v4_setup.edgeql
+++ b/tests/schemas/dump_v4_setup.edgeql
@@ -47,3 +47,7 @@ CONFIGURE CURRENT DATABASE INSERT ext::_conf::SecretObj {
     value := 'spam',
     secret := '123456',
 };
+
+CONFIGURE CURRENT DATABASE INSERT ext::auth::UIConfig {
+    redirect_to := 'http://example.edgedb.com'
+};
diff --git a/tests/test_dump_v4.py b/tests/test_dump_v4.py
--- a/tests/test_dump_v4.py
+++ b/tests/test_dump_v4.py
@@ -98,7 +98,7 @@ async def _ensure_schema_data_integrity(self):
 
 
 class TestDumpV4(tb.StableDumpTestCase, DumpTestCaseMixin):
-    EXTENSIONS = ["pgvector", "_conf"]
+    EXTENSIONS = ["pgvector", "_conf", "pgcrypto", "auth"]
     BACKEND_SUPERUSER = True
 
     SCHEMA_DEFAULT = os.path.join(os.path.dirname(__file__), 'schemas',
Repository: edgedb/edgedb

Issue:
test_server_proto.TestServerProtoMigration test teardown is flaky
It flaked 3 times during the 4.0 release build:
```
================================================================================
ERROR: tearDownClass (test_server_proto.TestServerProtoMigration)
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/testbase/server.py", line 843, in tearDownClass
    cls.loop.run_until_complete(cls.teardown_and_disconnect())
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/testbase/server.py", line 1149, in teardown_and_disconnect
    await drop_db(cls.admin_conn, dbname)
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/testbase/server.py", line 649, in drop_db
    await conn.execute(
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edgedb/abstract.py", line 297, in execute
    await self._execute(ExecuteContext(
  File "/usr/lib/x86_64-linux-gnu/edgedb-server-4/lib/python3.11/site-packages/edb/testbase/connection.py", line 382, in _execute
    await self._protocol.execute(
  File "edgedb/protocol/protocol.pyx", line 559, in execute
  File "edgedb/protocol/protocol.pyx", line 392, in _execute
  File "edgedb/protocol/asyncio_proto.pyx", line 62, in wait_for_message
edgedb.errors.ClientConnectionClosedError
```

I think that the reason this started showing up now is because of https://github.com/edgedb/edgedb/pull/6399; previously teardown errors would often be suppressed.


Discussion:

Resolving patch:
diff --git a/edb/testbase/server.py b/edb/testbase/server.py
--- a/edb/testbase/server.py
+++ b/edb/testbase/server.py
@@ -642,7 +642,7 @@ async def drop_db(conn, dbname):
     # with a retry loop. Without this, tests would flake
     # a lot.
     async for tr in TestCase.try_until_succeeds(
-        ignore=edgedb.ExecutionError,
+        ignore=(edgedb.ExecutionError, edgedb.ClientConnectionError),
         timeout=30
     ):
         async with tr:


Test patch:
Repository: edgedb/edgedb

Issue:
Automatically allow configured `redirect_to` URLs in auth extension
At the moment we require that _any_ redirect URL/domain is explicitly configured. We automatically allow the built-in UI, but we do not automatically allow the configured `redirect_to` and `redirect_to_on_signup` values that are configured in the built-in UI configuration.


Discussion:

Resolving patch:
diff --git a/edb/server/protocol/auth_ext/http.py b/edb/server/protocol/auth_ext/http.py
--- a/edb/server/protocol/auth_ext/http.py
+++ b/edb/server/protocol/auth_ext/http.py
@@ -1386,6 +1386,17 @@ def _is_url_allowed(self, url: str) -> bool:
         allowed_urls = cast(FrozenSet[str], allowed_urls).union(
             {self.base_path}
         )
+
+        ui_config = self._get_ui_config()
+        if ui_config:
+            allowed_urls = allowed_urls.union(
+                {ui_config.redirect_to}
+            )
+            if ui_config.redirect_to_on_signup:
+                allowed_urls = allowed_urls.union(
+                    {ui_config.redirect_to_on_signup}
+                )
+
         lower_url = url.lower()
 
         for allowed_url in allowed_urls:


Test patch:
Repository: edgedb/edgedb

Issue:
Don't join against __type__ when injecting type ids
See https://github.com/edgedb/edgedb/commit/006308ffe2006b38c08163e1db373abda77f0ac0, which broke it


Discussion:

Resolving patch:
diff --git a/edb/pgsql/compiler/pathctx.py b/edb/pgsql/compiler/pathctx.py
--- a/edb/pgsql/compiler/pathctx.py
+++ b/edb/pgsql/compiler/pathctx.py
@@ -1087,6 +1087,19 @@ def has_type_rewrite(
     )
 
 
+def link_needs_type_rewrite(
+        typeref: irast.TypeRef, *, env: context.Environment) -> bool:
+    return (
+        has_type_rewrite(typeref, env=env)
+        # Typically we need to apply rewrites when looking at a link
+        # target that has a policy on it, but we suppress this for
+        # schema::ObjectType. None of the hidden objects should be
+        # user visible anyway, and this allows us to do type id
+        # injection without a join.
+        and str(typeref.real_material_type.name_hint) != 'schema::ObjectType'
+    )
+
+
 def find_path_output(
     rel: pgast.BaseRelation, ref: pgast.BaseExpr
 ) -> Optional[pgast.OutputVar]:
@@ -1145,7 +1158,7 @@ def _get_path_output(
             and src_rptr.real_material_ptr.out_cardinality.is_multi()
             and not irtyputils.is_free_object(src_path_id.target)
         )
-        and not has_type_rewrite(src_path_id.target, env=env)
+        and not link_needs_type_rewrite(src_path_id.target, env=env)
     ):
         # A value reference to Object.id is the same as a value
         # reference to the Object itself. (Though we want to only
diff --git a/edb/pgsql/compiler/relgen.py b/edb/pgsql/compiler/relgen.py
--- a/edb/pgsql/compiler/relgen.py
+++ b/edb/pgsql/compiler/relgen.py
@@ -1089,7 +1089,8 @@ def process_set_as_path(
             and not source_rptr.is_inbound
             and not irtyputils.is_computable_ptrref(source_rptr.ptrref)
             and not irutils.is_type_intersection_reference(ir_set)
-            and not pathctx.has_type_rewrite(ir_source.typeref, env=ctx.env)):
+            and not pathctx.link_needs_type_rewrite(
+                ir_source.typeref, env=ctx.env)):
 
         src_src_is_visible = ctx.scope_tree.is_visible(
             source_rptr.source.path_id)


Test patch:
diff --git a/tests/test_edgeql_sql_codegen.py b/tests/test_edgeql_sql_codegen.py
--- a/tests/test_edgeql_sql_codegen.py
+++ b/tests/test_edgeql_sql_codegen.py
@@ -294,3 +294,16 @@ def test_codegen_fts_search_no_score(self):
             sql,
             "fts::search score should not be serialized when not needed",
         )
+
+    def test_codegen_typeid_no_join(self):
+        sql = self._compile(
+            '''
+            select Issue { name, number, tid := .__type__.id }
+            '''
+        )
+
+        self.assertNotIn(
+            "edgedbstd",
+            sql,
+            "typeid injection shouldn't joining ObjectType table",
+        )