fix: resolve Dgraph type name from DType tag in mutation validation#27
Merged
matthewmcneely merged 1 commit intoJun 9, 2026
Merged
Conversation
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.
matthewmcneely
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
AutoSchemais disabled, the pre-mutation schema check inclient.processderives the type name from the Go struct name (reflect.ValueOf(...).Type().Name()), while schema generation derives it from theDTypetag. For a struct whose Dgraph type differs from its Go name, the two disagree and every mutation is rejected:After
UpdateSchemaregisterstype MigrationLock, anInsertof this struct fails with: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
getNodeTypehelper, which reads theDTypevalue and falls back to the Go struct name. One line, plus a regression test that fails before the change and passes after.Test
TestMutateValidation_ResolvesDTypeNameregisters a type whose Dgraph name differs from its Go struct name and asserts the subsequentInsertpasses validation withAutoSchemadisabled.Summary by cubic
Fixes mutation validation to resolve the Dgraph type name from the
DTypetag (viagetNodeType) instead of the Go struct name whenAutoSchemais disabled. This prevents false “schema does not contain type …” errors for structs whose Dgraph type differs from their Go name.getNodeTypein the pre-mutation schema check to read theDTypetag and fall back to the struct name.TestMutateValidation_ResolvesDTypeNameto cover the mismatch case withAutoSchemadisabled.Written for commit 0717e38. Summary will update on new commits.