Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface errors when adding required constraint #8451

Open
kristojorg opened this issue Mar 7, 2025 · 0 comments
Open

Surface errors when adding required constraint #8451

kristojorg opened this issue Mar 7, 2025 · 0 comments

Comments

@kristojorg
Copy link

kristojorg commented Mar 7, 2025

When trying to set a required constraint on a link where there is existing data without that link, if you use an empty set as a fill value, migration will fail with an cryptic error when it should inform you that the required constraint cannot be set.

  • EdgeDB Version: 6.1+a41b539
  • EdgeDB CLI Version: Gel CLI 7.0.3+79e11b7
  • OS Version: Mac OS Sequoia 15.3.1

Steps to Reproduce:
I have not actually tried to reproduce it with these steps, but if I understand the problem correctly then this would work

  1. Create a type A with an optional link
type A {
  b: B
}
type B { }
  1. Run migration
  2. Insert an object of type A without the link
  3. Edit the schema to make the object required
type A {
  required b: B
}
type B { }
  1. Run the migration and select the default casting of an empty set as the fill expression: <B>{}
  2. See error in console### Error in console
gel error: InternalServerError: RuntimeError: unhandled error while calling interpret_backend_error(); run with EDGEDB_DEBUG_SERVER to debug.
  Hint: This is most likely a bug in Gel. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
  Server traceback:
      edb.errors.InternalServerError: RuntimeError: unhandled error while calling interpret_backend_error(); run with EDGEDB_DEBUG_SERVER to debug.
Error executing command: error in one of the migrations

This error indicates there is a bug in Gel, which doesn't actually seem to be true. In order to debug, I had to dump and restore my cloud instance into a local instance and then try to run the migration and then access gel instance logs to see the postgres error.

The logs

INFO 82550 test-migration-2 2025-03-06T18:31:14.866 edb.server: Connection established to backend database: main
INFO 82550 test-migration-2 2025-03-06T18:32:01.515 edb.server: Connection established to backend database: __edgedbsys__
INFO 82550 test-migration-2 2025-03-06T18:32:01.515 edb.server: introspecting database '__edgedbsys__'
INFO 82550 test-migration-2 2025-03-06T18:32:02.729 edb.server: Backend connections to database __edgedbsys__: 1 were established in at least the last 1.0 seconds.
INFO 82550 test-migration-2 2025-03-06T18:32:56.794 edb.server: introspecting database 'main'
ERROR 82622 - 2025-03-06T18:33:37.615 postgres: column "3064f80a-faf4-11ef-8746-e76d48ed6221" of relation "f97dd274-dce9-11ef-82d4-53d4582f7aea" contains null values
INFO 82622 - 2025-03-06T18:33:37.615 postgres: SQL statement "ALTER TABLE edgedbpub."f97dd274-dce9-11ef-82d4-53d4582f7aea" ALTER COLUMN "3064f80a-faf4-11ef-8746-e76d48ed6221" SET NOT NULL"
INFO 82622 - 2025-03-06T18:33:37.615 postgres:  PL/pgSQL function inline_code_block line 287 at SQL statement
INFO 82622 - 2025-03-06T18:33:37.615 postgres: DO LANGUAGE plpgsql $__$
INFO 82622 - 2025-03-06T18:33:37.615 postgres:  DECLARE
INFO 82622 - 2025-03-06T18:33:37.615 postgres:      _dummy_text text;
INFO 82622 - 2025-03-06T18:33:37.615 postgres:  BEGIN
INFO 82622 - 2025-03-06T18:33:37.615 postgres: 
INFO 82622 - 2025-03-06T18:33:37.615 postgres:                  SELECT
INFO 82622 - 2025-03-06T18:33:37.615 postgres:                      edgedb_v6_2f20b3fed0.raise_on_not_null(
INFO 82622 - 2025-03-06T18:33:37.615 postgres:                          (SELECT NULLIF(
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              (SELECT
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                                  version::text
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              FROM
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                                  edgedb_v6_2f20b3fed0."_SchemaSchemaVersion"
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              FOR UPDATE),
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              '1584ffda-faf4-11ef-88f9-59e1e15e4aae'
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                          )),
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                          'serialization_failure',
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                          msg => (
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              'Cannot serialize DDL: '
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                              || (SELECT version::text FROM
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                                  edgedb_v6_2f20b3fed0."_SchemaSchemaVersion")
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                          )
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                      )
INFO 82622 - 2025-03-06T18:33:37.616 postgres:                  INTO _dummy_text;
INFO 82622 - 2025-03-06T18:33:37.616 postgres: 
INFO 82622 - 2025-03-06T18:33:37.616 postgres:  CREATE TABLE edgedbpub."3053f622-faf4-11ef-b2fa-6d59ba0f3948" ();
INFO 82622 - 2025-03-06T18:33:37.616 postgres: 
INFO 82622 - 2025-03-06T18:33:37.616 postgres:  COMMENT ON TABLE edgedbpub."3053f622-faf4-11ef-b2fa-6d59ba0f3948" IS 'object type ''default:...
INFO 82622 - 2025-03-06T18:33:52.253 postgres: checkpoint starting: time
ERROR 82622 - 2025-03-06T18:34:47.693 postgres: column "5a2c30b8-faf4-11ef-beb7-11ff47f03079" of relation "f97dd274-dce9-11ef-82d4-53d4582f7aea" contains null values
INFO 82622 - 2025-03-06T18:34:47.693 postgres: SQL statement "ALTER TABLE edgedbpub."f97dd274-dce9-11ef-82d4-53d4582f7aea" ALTER COLUMN "5a2c30b8-faf4-11ef-beb7-11ff47f03079" SET NOT NULL"
INFO 82622 - 2025-03-06T18:34:47.693 postgres:  PL/pgSQL function inline_code_block line 287 at SQL statement
INFO 82622 - 2025-03-06T18:34:47.693 postgres: DO LANGUAGE plpgsql $__$
INFO 82622 - 2025-03-06T18:34:47.693 postgres:  DECLARE
INFO 82622 - 2025-03-06T18:34:47.693 postgres:      _dummy_text text;
INFO 82622 - 2025-03-06T18:34:47.693 postgres:  BEGIN
INFO 82622 - 2025-03-06T18:34:47.693 postgres: 
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                  SELECT
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                      edgedb_v6_2f20b3fed0.raise_on_not_null(
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                          (SELECT NULLIF(
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              (SELECT
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                                  version::text
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              FROM
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                                  edgedb_v6_2f20b3fed0."_SchemaSchemaVersion"
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              FOR UPDATE),
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              '1584ffda-faf4-11ef-88f9-59e1e15e4aae'
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                          )),
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                          'serialization_failure',
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                          msg => (
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              'Cannot serialize DDL: '
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                              || (SELECT version::text FROM
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                                  edgedb_v6_2f20b3fed0."_SchemaSchemaVersion")
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                          )
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                      )
INFO 82622 - 2025-03-06T18:34:47.693 postgres:                  INTO _dummy_text;
INFO 82622 - 2025-03-06T18:34:47.693 postgres: 
INFO 82622 - 2025-03-06T18:34:47.693 postgres:  CREATE TABLE edgedbpub."5a1aca58-faf4-11ef-b3c4-6d38bb079e63" ();
INFO 82622 - 2025-03-06T18:34:47.693 postgres: 
INFO 82622 - 2025-03-06T18:34:47.693 postgres:  COMMENT ON TABLE edgedbpub."5a1aca58-faf4-11ef-b3c4-6d38bb079e63" IS 'object type ''default:...
INFO 82550 test-migration-2 2025-03-06T18:34:52.589 edb.server: Connection discarded to backend database: main
INFO 82550 test-migration-2 2025-03-06T18:34:52.589 edb.server: Connection discarded to backend database: __edgedbsys__
INFO 82550 test-migration-2 2025-03-06T18:36:52.587 edb.server: Connection discarded to backend database: main

As you can see, the error came from a null value being found.

What to improve

  1. Surface the underlying postgres error as a gel error (Failed to set constraint required due to missing values)
  2. Allow accessing the postgres logs of a cloud instance either via the console or via the logs in the cloud UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant