Skip to content

Cannot Add Abstract Type Parent to Existing Types #9120

@craigdrayton

Description

@craigdrayton

GEL Migration Bug: Cannot Add Abstract Type Parent to Existing Types

Date: 2025-01-20
GEL Version: 6.11+66a1377
Severity: High - Blocks adding new abstract types to existing schemas


Summary

GEL migration generator fails with InvalidConstraintDefinitionError: constraints on object types must have an 'on' clause when attempting to add a new abstract type as a parent to existing concrete types, even when the abstract type contains no type-level constraints.


Reproduction Steps

Step 1: Start with existing schema

Create initial migration with abstract types and concrete types:

# base.gel
abstract type Versioned { ... }
abstract type SoftDeletable { ... }

# concept.gel
type Concept extending Versioned, SoftDeletable { ... }

Apply migration → Works fine.

Step 2: Add new abstract type to schema

# base.gel - ADD NEW ABSTRACT TYPE
abstract type Proposable {
  required property status -> ProposalStatus {
    default := ProposalStatus.confirmed;
  }
}

Create migration, apply → Works fine (abstract type created).

Step 3: Extend existing type with new abstract type

# concept.gel - EXTEND WITH NEW ABSTRACT TYPE
type Concept extending Versioned, SoftDeletable, Proposable { ... }

Run gel migration create --non-interactive

Result: ❌ Migration fails with error:

gel error: InvalidConstraintDefinitionError: constraints on object types must have an 'on' clause

Expected Behavior

Migration should succeed with DDL similar to:

ALTER TYPE default::Concept EXTENDING Proposable;

Actual Behavior

Migration generation fails immediately with constraint error, even though:

  • Proposable has no type-level constraint expression on (...)
  • The error message is misleading (no constraints need fixing)
  • The same schema works fine if created in initial migration

Workaround

Delete all migrations and recreate from scratch with the new abstract type included in the initial migration. This works because GEL can handle CREATE TYPE ... EXTENDING AbstractType but cannot handle ALTER TYPE ... EXTENDING AbstractType.

Workaround steps:

  1. Destroy database instances
  2. Delete all migration files
  3. Run gel migration create to generate initial migration with both old and new abstract types
  4. Run gel migrate to apply

Minimal Test Case

File: base.gel

module default {
  abstract type Proposable {
    required property test -> bool {
      default := false;
    }
  }
}

File: concept.gel

module default {
  type Concept {
    required property name -> str;
  }
}

Steps:

  1. Create initial migration → Apply
  2. Edit concept.gel: type Concept extending Proposable { ... }
  3. Run gel migration create --non-interactive
  4. Error occurs

Additional Context

  • Works fine when abstract type and extensions are in same migration (initial migration)
  • Fails when trying to add abstract type parent to existing concrete type in later migration
  • Error message is misleading - suggests constraint syntax issue but no constraints are malformed
  • Same pattern works fine for other schema operations (adding properties, links, etc.)
  • Other abstract types (Versioned, SoftDeletable, Auditable) work because they were in initial migration

Environment

  • OS: Windows (WSL)
  • GEL Version: 6.11+66a1377
  • Installation Method: WSL
  • Command: gel migration create --non-interactive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions