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

Issue:
Add `rm-data-dir` command to `edb`
The option should remove the default data directory in the case of version conflict. 




Discussion:

Resolving patch:
diff --git a/edb/tools/edb.py b/edb/tools/edb.py
--- a/edb/tools/edb.py
+++ b/edb/tools/edb.py
@@ -60,6 +60,7 @@ def server(version=False, **kwargs):
 # Import at the end of the file so that "edb.tools.edb.edbcommands"
 # is defined for all of the below modules when they try to import it.
 from . import cli  # noqa
+from . import rm_data_dir  # noqa
 from . import dflags  # noqa
 from . import gen_errors  # noqa
 from . import gen_types  # noqa
diff --git a/edb/tools/rm_data_dir.py b/edb/tools/rm_data_dir.py
new file mode 100644
--- /dev/null
+++ b/edb/tools/rm_data_dir.py
@@ -0,0 +1,34 @@
+#
+# This source file is part of the EdgeDB open source project.
+#
+# Copyright 2021-present MagicStack Inc. and the EdgeDB authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+import shutil
+
+from edb.common import devmode
+from edb.tools.edb import edbcommands
+
+
+@edbcommands.command("rm-data-dir")
+def rm_data_dir():
+    """Remove the local development data directory if present"""
+    data_dir = devmode.get_dev_mode_data_dir()
+    if data_dir.exists():
+        shutil.rmtree(data_dir)
+        print("Removed the local dev data directory.")
+    else:
+        print("The local dev data directory does not exist.")


Test patch:
Repository: edgedb/edgedb

Issue:
EdgeDB doesn't work with managed postgres on Digital Ocean
<!-- Please search existing issues to avoid creating duplicates. -->

- EdgeDB Version: 2.12

Steps to Reproduce:

1. Follow the [digital ocean deployment guide using a managed postgres](https://www.edgedb.com/docs/guides/deployment/digitalocean#deploy-with-managed-postgresql) It will fail after setting the backend dsn and restarting edgedb.



Discussion:
The error is the same as what we get in this failing CI job https://github.com/edgedb/edgedb/actions/runs/4329038078/jobs/7559309957

Resolving patch:
diff --git a/edb/server/pgcluster.py b/edb/server/pgcluster.py
--- a/edb/server/pgcluster.py
+++ b/edb/server/pgcluster.py
@@ -901,6 +901,7 @@ async def _detect_capabilities(
         conn: pgcon.PGConnection,
     ) -> pgparams.BackendCapabilities:
         from edb.server import pgcon
+        from edb.server.pgcon import errors
 
         caps = pgparams.BackendCapabilities.NONE
 
@@ -966,6 +967,15 @@ async def _detect_capabilities(
             )
         except pgcon.BackendPrivilegeError:
             can_make_superusers = False
+        except pgcon.BackendError as e:
+            if e.code_is(
+                errors.ERROR_INTERNAL_ERROR
+            ) and "not in permitted superuser list" in str(e):
+                # DigitalOcean raises a custom error:
+                # XX000: Role ... not in permitted superuser list
+                can_make_superusers = False
+            else:
+                raise
         else:
             can_make_superusers = True
         finally:


Test patch:
Repository: edgedb/edgedb

Issue:
Leading dot notation should not appear in `insert` shapes
The following query should not be compiled and executed successfully:

```
insert Person {name := "<name>", friends := .friends};
```


Discussion:

Resolving patch:
diff --git a/edb/edgeql/compiler/viewgen.py b/edb/edgeql/compiler/viewgen.py
--- a/edb/edgeql/compiler/viewgen.py
+++ b/edb/edgeql/compiler/viewgen.py
@@ -1245,6 +1245,7 @@ def _compile_qlexpr(
     ptrsource: s_sources.Source,
     ptr_name: sn.QualName,
     is_linkprop: bool,
+    should_set_partial_prefix: bool,
     s_ctx: ShapeContext,
     ctx: context.ContextLevel,
 ) -> Tuple[irast.Set, context.ViewRPtr]:
@@ -1268,7 +1269,9 @@ def _compile_qlexpr(
         source_set = setgen.fixup_computable_source_set(
             ir_source, ctx=shape_expr_ctx
         )
-        shape_expr_ctx.partial_path_prefix = source_set
+
+        if should_set_partial_prefix:
+            shape_expr_ctx.partial_path_prefix = source_set
 
         if s_ctx.exprtype.is_mutation() and ptrcls is not None:
             shape_expr_ctx.expr_exposed = context.Exposure.EXPOSED
@@ -1438,6 +1441,7 @@ def _normalize_view_ptr_expr(
                 ptrsource=ptrsource,
                 ptr_name=ptr_name,
                 is_linkprop=is_linkprop,
+                should_set_partial_prefix=True,
                 s_ctx=s_ctx,
                 ctx=ctx,
             )
@@ -1521,6 +1525,10 @@ def _normalize_view_ptr_expr(
             ptrsource=ptrsource,
             ptr_name=ptr_name,
             is_linkprop=is_linkprop,
+            # do not set partial path prefix if in the insert
+            # shape but not in defaults
+            should_set_partial_prefix=(
+                not s_ctx.exprtype.is_insert() or from_default),
             s_ctx=s_ctx,
             ctx=ctx,
         )


Test patch:
diff --git a/tests/test_edgeql_insert.py b/tests/test_edgeql_insert.py
--- a/tests/test_edgeql_insert.py
+++ b/tests/test_edgeql_insert.py
@@ -86,6 +86,15 @@ async def test_edgeql_insert_fail_5(self):
                 INSERT Person.notes { name := "note1" };
             ''')
 
+    async def test_edgeql_insert_fail_6(self):
+        with self.assertRaisesRegex(
+            edgedb.QueryError,
+            r"could not resolve partial path",
+        ):
+            await self.con.execute('''
+                INSERT Person { name := .name };
+            ''')
+
     async def test_edgeql_insert_simple_01(self):
         await self.con.execute(r"""
             INSERT InsertTest {
Repository: edgedb/edgedb

Issue:
Suggest multi link if user tries to create a link array
When a user tries `link foo -> array<MyObject>`, suggest instead `multi link foo -> MyObject` in the error that `migration create` returns.


Discussion:

Resolving patch:
diff --git a/edb/schema/links.py b/edb/schema/links.py
--- a/edb/schema/links.py
+++ b/edb/schema/links.py
@@ -36,11 +36,11 @@
 from . import pointers
 from . import referencing
 from . import sources
+from . import types as s_types
 from . import utils
 
 if TYPE_CHECKING:
     from . import objtypes as s_objtypes
-    from . import types as s_types
     from . import schema as s_schema
 
 
@@ -254,10 +254,19 @@ def validate_object(
 
         if not target.is_object_type():
             srcctx = self.get_attribute_source_context('target')
+            if isinstance(target, s_types.Array):
+                # Custom error message for link -> array<...>
+                link_dn = scls.get_displayname(schema)
+                el_dn = target.get_subtypes(schema)[0].get_displayname(schema)
+                hint = f"did you mean 'multi link {link_dn} -> {el_dn}'?"
+            else:
+                hint = None
+
             raise errors.InvalidLinkTargetError(
                 f'invalid link target type, expected object type, got '
                 f'{target.get_verbosename(schema)}',
                 context=srcctx,
+                hint=hint,
             )
 
         if target.is_free_object_type(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
@@ -2096,6 +2096,30 @@ async def test_edgeql_ddl_link_target_bad_04(self):
                 };
             ''')
 
+    async def test_edgeql_ddl_link_target_bad_05(self):
+        with self.assertRaisesRegex(
+            edgedb.InvalidLinkTargetError,
+            r"invalid link target type, expected object type, got.+array",
+            _hint="did you mean 'multi link bar -> default::Foo'?",
+        ):
+            await self.con.execute('''
+                create type Foo {
+                    create link bar -> array<Foo>;
+                };
+            ''')
+
+    async def test_edgeql_ddl_link_target_bad_06(self):
+        with self.assertRaisesRegex(
+            edgedb.InvalidLinkTargetError,
+            r"invalid link target type, expected object type, got.+array",
+            _hint="did you mean 'multi link bar -> default::Foo'?",
+        ):
+            await self.con.execute('''
+                create type Foo {
+                    create multi link bar -> array<Foo>;
+                };
+            ''')
+
     async def test_edgeql_ddl_link_target_merge_01(self):
         await self.con.execute('''
Repository: edgedb/edgedb

Issue:
INTERSECT/EXCEPT on three builtin objects fails
```
select std::BaseObject EXCEPT schema::Object INTERSECT schema::TupleElement;
```
and
```
select std::BaseObject INTERSECT schema::Object INTERSECT schema::TupleElement;
```
fail at
```
        File "/home/sully/src/e/edgedb/edb/pgsql/compiler/pathctx.py", line 414, in _get_path_var_in_setop
          assert counts == [counts[0]] * len(counts)
```
which is a good time. Seems to be access policy related.


Discussion:
Oh it happens with unions too

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
@@ -1095,15 +1095,18 @@ def _get_path_output(
     ref: pgast.BaseExpr
     alias = None
     rptr = path_id.rptr()
-    if rptr is not None and irtyputils.is_id_ptrref(rptr) and (
-        src_path_id := path_id.src_path()
-    ) and not (
-        (src_rptr := src_path_id.rptr())
-        and (
-            src_rptr.real_material_ptr.out_cardinality.is_multi()
+    if (
+        rptr is not None
+        and irtyputils.is_id_ptrref(rptr)
+        and (src_path_id := path_id.src_path())
+        and not disable_output_fusion
+        and not (
+            (src_rptr := src_path_id.rptr())
+            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 has_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
         # apply this in the cases that process_set_as_path does this


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
@@ -2955,6 +2955,29 @@ async def test_edgeql_select_setops_28(self):
             ],
         )
 
+    async def test_edgeql_select_setops_29(self):
+        # These queries all produced compiler ISEs in the past
+        # The results aren't super important, so just run them
+        await self.con.query('''
+            select std::BaseObject
+                UNION schema::Object UNION schema::TupleElement;
+        ''')
+
+        await self.con.query('''
+            select std::BaseObject
+                EXCEPT schema::Object EXCEPT schema::TupleElement;
+        ''')
+
+        await self.con.query('''
+            select std::BaseObject
+                EXCEPT schema::Object INTERSECT schema::TupleElement;
+        ''')
+
+        await self.con.query('''
+            select std::BaseObject
+                INTERSECT schema::Object INTERSECT schema::TupleElement;
+        ''')
+
     async def test_edgeql_select_order_01(self):
         await self.assert_query_result(
             r'''
Repository: edgedb/edgedb

Issue:
Can't create a database that shares a name with a standard library function
```
edgedb> create database range;
edgedb error: SchemaError: function 'std::range(lower: OPTIONAL std::anypoint={}, upper: OPTIONAL std::anypoint={}, NAMED ONLY inc_lower: std::bool=true, NAMED ONLY inc_upper: std::bool=false, NAMED ONLY empty: std::bool=false)' already exists
```


Discussion:

Resolving patch:
diff --git a/edb/schema/database.py b/edb/schema/database.py
--- a/edb/schema/database.py
+++ b/edb/schema/database.py
@@ -99,7 +99,8 @@ def validate_create(
         schema: s_schema.Schema,
         context: sd.CommandContext,
     ) -> None:
-        super().validate_create(schema, context)
+        # no call to super().validate_create() as we don't want to enforce
+        # rules that hold for any other schema objects
         self._validate_name(schema, context)
 
 
diff --git a/edb/schema/delta.py b/edb/schema/delta.py
--- a/edb/schema/delta.py
+++ b/edb/schema/delta.py
@@ -2920,9 +2920,9 @@ def validate_create(
         context: CommandContext,
     ) -> None:
         # Check if functions by this name exist
-        fn = self.get_attribute_value('name')
-        if fn is not None and not sn.is_fullname(str(fn)):
-            funcs = schema.get_functions(fn, tuple())
+        obj_name = self.get_attribute_value('name')
+        if obj_name is not None and not sn.is_fullname(str(obj_name)):
+            funcs = schema.get_functions(obj_name, tuple())
             if funcs:
                 raise errors.SchemaError(
                     f'{funcs[0].get_verbosename(schema)} already exists')


Test patch:
diff --git a/tests/test_database.py b/tests/test_database.py
--- a/tests/test_database.py
+++ b/tests/test_database.py
@@ -76,6 +76,22 @@ async def test_database_create_03(self):
         finally:
             await tb.drop_db(self.con, 'databasename')
 
+    async def test_database_create_04(self):
+        if not self.has_create_database:
+            self.skipTest("create database is not supported by the backend")
+
+        # create database name that conflicts with names in schema
+        await self.con.execute('CREATE DATABASE range;')
+
+        conn = await self.connect(database='range')
+
+        res = await conn.query('select range(5, 10)')
+        self.assertEqual(res, [edgedb.Range(5, 10)])
+
+        await conn.aclose()
+
+        await tb.drop_db(self.con, 'range')
+
     async def test_database_drop_01(self):
         if not self.has_create_database:
             self.skipTest("create database is not supported by the backend")
Repository: edgedb/edgedb

Issue:
Link property on properties are parsed incorrectly
Version: EdgeDB 3.0-dev.7454+local (repl 3.0.0-dev)


This schema is not processed correctly.
```
type Test1 {
    title : str {
        sub_title : str
    }
}
```

The query result is 
```
edgedb> describe type Test1 as sdl;
{
  'type default::Test1 {
    property sub_title: std::str;
    property title: std::str;
};',
}
```


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
@@ -639,6 +639,16 @@ def _trace_item_layout(
     for decl in node.commands:
         if isinstance(decl, qlast.CreateConcretePointer):
             assert isinstance(obj, qltracer.Source)
+
+            # do not allow link property on properties
+            if isinstance(node, qlast.CreateConcreteProperty):
+                raise errors.InvalidDefinitionError(
+                    f'cannot create a link property on a property',
+                    context=decl.context,
+                    hint='Link properties can only be created on links, whose '
+                         'target types are object types.',
+                )
+
             target: Optional[qltracer.TypeLike]
             target_expr: Optional[qlast.Expr]
             if isinstance(decl.target, qlast.TypeExpr):


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -351,6 +351,17 @@ def test_schema_bad_link_06(self):
             type T { multi link following extending abs -> T {using (T)} }
         """
 
+    @tb.must_fail(errors.InvalidDefinitionError,
+                  "cannot create a link property on a property")
+    def test_schema_link_prop_on_prop_01(self):
+        """
+            type Test1 {
+                title : str {
+                    sub_title : str
+                }
+            };
+        """
+
     @tb.must_fail(errors.InvalidPropertyTargetError,
                   "invalid property type: expected a scalar type, "
                   "or a scalar collection, got object type 'test::Object'",
Repository: edgedb/edgedb

Issue:
Database reconnects when querying range and output is json-pretty or json-lines
- EdgeDB Version: "2.15+75c3494" and "3.0-rc.1+5979043"
- EdgeDB CLI Version: 3.0.0-beta.1+487c517
- OS Version: Windows 11

Steps to Reproduce:

1. Start REPL
2. \set output-format json-pretty or \set output-format json-lines
3. type `select range(1, 10);` or any other type of range

The output is:

```
edgedb> select range(1, 10);
edgedb error: cannot decode json result: expected value at line 1 column 1
Reconnecting...
Connecting to an EdgeDB instance at localhost:10709...
```

(All in all the reconnnect takes about 1.5 seconds)

Meanwhile if the output format is set to `\set output-format tab-separated` then the same query gives an instant error more along the lines of what one would expect and no reconnecting.

```
Error: Complex objects like Range(Range { lower: Some(Int64(1)), upper: Some(Int64(10)), inc_lower: true, inc_upper: false, empty: false }) cannot be printed tab-separated
```


Discussion:

Resolving patch:
diff --git a/edb/pgsql/compiler/output.py b/edb/pgsql/compiler/output.py
--- a/edb/pgsql/compiler/output.py
+++ b/edb/pgsql/compiler/output.py
@@ -563,6 +563,11 @@ def serialize_expr_to_json(
             # Use the actual generic helper for converting anyrange to jsonb
             name=('edgedb', 'range_to_jsonb'),
             args=[expr], null_safe=True, ser_safe=True)
+        if env.output_format in _JSON_FORMATS:
+            val = pgast.TypeCast(
+                arg=val,
+                type_name=pgast.TypeName(name=('json',))
+            )
 
     elif irtyputils.is_collection(styperef) and not expr.ser_safe:
         val = coll_as_json_object(expr, styperef=styperef, env=env)
@@ -579,6 +584,11 @@ def serialize_expr_to_json(
         val = pgast.FuncCall(
             name=common.get_cast_backend_name(cast_name, aspect='function'),
             args=[expr], null_safe=True, ser_safe=True)
+        if env.output_format in _JSON_FORMATS:
+            val = pgast.TypeCast(
+                arg=val,
+                type_name=pgast.TypeName(name=('json',))
+            )
 
     elif not nested:
         val = pgast.FuncCall(


Test patch:
Repository: edgedb/edgedb

Issue:
arrays of ranges format wrong in json output mode
```
edgedb> select ([range(1, 10)]);
[["[1,10)"]]
```

But doing an explicit cast works:
```
edgedb> select <json>([range(1, 10)]);
[[{"lower": 1, "upper": 10, "inc_lower": true, "inc_upper": false}]]
```

This happens for the pending pgvector type, but weirdly does *not* happen for bytes, the other type with a custom json output.


Discussion:

Resolving patch:
diff --git a/edb/pgsql/compiler/output.py b/edb/pgsql/compiler/output.py
--- a/edb/pgsql/compiler/output.py
+++ b/edb/pgsql/compiler/output.py
@@ -156,8 +156,12 @@ def array_as_json_object(
     el_type = styperef.subtypes[0]
 
     is_tuple = irtyputils.is_tuple(el_type)
-    # Tuples and bytes might need underlying casts to be done
-    if is_tuple or irtyputils.is_bytes(el_type):
+    # Tuples/ranges/scalars with custom casts need underlying casts to be done
+    if (
+        is_tuple
+        or irtyputils.is_range(el_type)
+        or el_type.real_base_type.needs_custom_json_cast
+    ):
         coldeflist = []
 
         out_alias = env.aliases.get('q')
@@ -198,7 +202,6 @@ def array_as_json_object(
 
             needs_unnest = bool(el_type.subtypes)
         else:
-            assert not el_type.subtypes
             val = pgast.ColumnRef(name=[out_alias])
             agg_arg = serialize_expr_to_json(
                 val, styperef=el_type, nested=True, env=env)


Test patch:
diff --git a/tests/test_edgeql_expressions.py b/tests/test_edgeql_expressions.py
--- a/tests/test_edgeql_expressions.py
+++ b/tests/test_edgeql_expressions.py
@@ -6716,6 +6716,20 @@ async def test_edgeql_expr_range_38(self):
             [edgedb.Range(0, 10)],
         )
 
+    async def test_edgeql_expr_range_39(self):
+        await self.assert_query_result(
+            r'''
+                select [range(1, 10)];
+            ''',
+            [
+                [
+                    {"lower": 1, "upper": 10,
+                     "inc_lower": True, "inc_upper": False},
+                ]
+            ],
+            json_only=True,
+        )
+
     async def test_edgeql_expr_cannot_assign_id_01(self):
         with self.assertRaisesRegex(
                 edgedb.QueryError, r'cannot assign to id'):
Repository: edgedb/edgedb

Issue:
ISE when creating a scalar inheriting from an abstract scalar and a non-abstract scalar
```
abstract scalar type non_empty_str extending str {
    constraint min_len_value(1);
}

scalar type name_str extending str {
    constraint max_len_value(40);
}

scalar type required_name_str extending non_empty_str, name_str;
```

RESULT:

```
➜  edgedb git:(dev) ✗ edgedb -I <project_name> migrate
edgedb error: InternalServerError: type "edgedbpub.615f49c8-6117-11ed-b3bf-5d058c5f93bb_domain" does not exist
  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: type "edgedbpub.615f49c8-6117-11ed-b3bf-5d058c5f93bb_domain" does not exist
```


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
@@ -2045,8 +2045,10 @@ def constraint_is_effective(cls, schema, constraint):
                 return has_table(subject.get_source(schema), schema)
         elif isinstance(subject, s_objtypes.ObjectType):
             return has_table(subject, schema)
+        elif isinstance(subject, s_scalars.ScalarType):
+            return not subject.get_abstract(schema)
         else:
-            return True
+            raise NotImplementedError()
 
     @classmethod
     def fixup_base_constraint_triggers(


Test patch:
diff --git a/tests/test_constraints.py b/tests/test_constraints.py
--- a/tests/test_constraints.py
+++ b/tests/test_constraints.py
@@ -1753,3 +1753,23 @@ async def test_constraints_no_refs(self):
             };
         """
         )
+
+    async def test_constraints_abstract_scalar(self):
+        await self.con.execute(
+            """
+            create abstract scalar type posint64 extending int64 {
+                create constraint min_value(0);
+            };
+
+            create scalar type limited_int64 extending posint64;
+
+            create type X {
+                create property y -> limited_int64;
+            };
+            """
+        )
+        await self.con.execute("insert X { y := 1 }")
+        async with self.assertRaisesRegexTx(
+            edgedb.ConstraintViolationError, "Minimum allowed value for"
+        ):
+            await self.con.execute("insert X { y := -1 }")