Skip to content

fix: resolve Dgraph type name from DType tag in mutation validation#27

Merged
matthewmcneely merged 1 commit into
matthewmcneely:mainfrom
mlwelles:fix/autoschema-dtype-validation
Jun 9, 2026
Merged

fix: resolve Dgraph type name from DType tag in mutation validation#27
matthewmcneely merged 1 commit into
matthewmcneely:mainfrom
mlwelles:fix/autoschema-dtype-validation

Conversation

@mlwelles

@mlwelles mlwelles commented Jun 9, 2026

Copy link
Copy Markdown

Problem

When AutoSchema is disabled, the pre-mutation schema check in client.process derives the type name from the Go struct name (reflect.ValueOf(...).Type().Name()), while schema generation derives it from the DType tag. For a struct whose Dgraph type differs from its Go name, the two disagree and every mutation is rejected:

type migrationLock struct {
    DType []string `json:"dgraph.type,omitempty" dgraph:"MigrationLock"`
    // ...
}

After UpdateSchema registers type MigrationLock, an Insert of this struct fails with:

schema validation failed: database schema does not contain type migrationLock

even though the schema contains type MigrationLock. This breaks any AutoSchema-disabled workflow whose Go struct name differs from its Dgraph type name (for example, schema-migration tooling that keeps its bookkeeping types unexported).

Fix

Resolve the type name in the validation the same way mutations and schema generation already do — via the existing getNodeType helper, which reads the DType value and falls back to the Go struct name. One line, plus a regression test that fails before the change and passes after.

Test

TestMutateValidation_ResolvesDTypeName registers a type whose Dgraph name differs from its Go struct name and asserts the subsequent Insert passes validation with AutoSchema disabled.


Summary by cubic

Fixes mutation validation to resolve the Dgraph type name from the DType tag (via getNodeType) instead of the Go struct name when AutoSchema is disabled. This prevents false “schema does not contain type …” errors for structs whose Dgraph type differs from their Go name.

  • Bug Fixes
    • Use getNodeType in the pre-mutation schema check to read the DType tag and fall back to the struct name.
    • Add regression test TestMutateValidation_ResolvesDTypeName to cover the mismatch case with AutoSchema disabled.

Written for commit 0717e38. Summary will update on new commits.

Review in cubic

The AutoSchema-disabled mutation guard derived the type name from the Go struct
name (reflect Type().Name()), while schema generation derives it from the DType
tag. A struct whose Dgraph type differs from its Go name — e.g.
modusGraph-migrate's migrationLock, declared dgraph:"MigrationLock" — then
failed validation with "schema does not contain type migrationLock" even though
the schema held "type MigrationLock". This broke migrate.Run on a fresh
database. Resolve the name via getNodeType, the same path mutations and schema
generation use, and add a regression test.
@mlwelles mlwelles requested a review from matthewmcneely as a code owner June 9, 2026 03:55

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@matthewmcneely matthewmcneely merged commit 5ec0c89 into matthewmcneely:main Jun 9, 2026
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants