Skip to content

bug: merge fails with SchemaNotFoundError when removing any schema node #9899

Description

@rvandepu

Component

API Server / GraphQL

Infrahub version

1.10.4 (SDK 1.20.1)

Current Behavior

Merging a branch (via a proposed change or infrahubctl branch merge) that removes any schema node fails. Both the Schema Integrity and Data Integrity validators pass and the proposed change is reported "eligible to be merged", but the merge task fails during migration calculation and rolls back:

infrahub.exceptions.SchemaNotFoundError:
    Unable to find the schema '<NodeKind>' in the registry
    main | <NodeKind>

Traceback path:
core/branch/tasks.py:_do_merge_branch (~L440) -> core/merge/branch_merger.py:calculate_migrations (L151) -> core/models.py:SchemaUpdateValidationResult.init -> process_diff (L194) -> core/schema/schema_branch.py:get (L405), which raises.

calculate_migrations builds the post-merge (target) schema, in which the node is already removed, then process_diff calls schema.get(name='<NodeKind>', duplicate=False) against that target schema and fails because the node is gone.

A secondary task also fails while serializing the exception:

TypeError: SchemaNotFoundError.__init__() missing 1 required positional argument: 'identifier'

The exception is not picklable (its __init__ requires identifier), so Prefect cannot round-trip it, which can mask the real error in some views.

Expected Behavior

The merge removes the node and completes. process_diff should resolve a removed schema element against the pre-merge (source/root) schema, or otherwise handle removals without raising SchemaNotFoundError. (Separately, SchemaNotFoundError should be picklable.)

Steps to Reproduce

Reproduced on a clean instance with fresh schema and zero objects; no inheritance or relationships required.

  1. Add a schema node to main:
    version: "1.0"
    nodes:
      - name: ReproSolo
        namespace: Testing
        attributes:
          - { name: name, kind: Text, unique: true }
  2. Create a branch and set that node state: absent (or delete it).
  3. Merge the branch to main (proposed-change merge or infrahubctl branch merge).
  4. The merge task fails: SchemaNotFoundError: Unable to find the schema 'TestingReproSolo' in the registry, then rolls back.

Additional Information

  • Reproduced on 1.10.4, fresh schema, zero objects. Happens for a standalone node and for a node that inherits a generic.
  • Removing the node via infrahubctl schema load directly (not via a merge) works. Only the merge path (calculate_migrations) is affected.
  • Removing relationships via a merge works; only node removal fails.
  • Both integrity validators pass; the failure is only at merge time.
  • Earlier failure on the same effort (a different bug, diff tracking after a branch rebase): bug: merge fails "Multiple diffs ... tracking_id" after branch rebase #9898.
  • A redacted diagnostic bundle is available on request.

Metadata

Metadata

Assignees

Labels

priority/1This issue must be fixed/implemented ASAP, it's a blocker for a releasestate/ai-pipeline-readytype/bugSomething isn't working as expected

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions