{"record":{"id":"1592819a8fc2e18c","repo":"gastownhall/beads","slug":"query-constraint-violations-w","errorCode":null,"errorMessage":"query constraint violations: %w","messagePattern":"query constraint violations: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/conflicts.go","lineNumber":525,"sourceCode":"\t\ttables = append(tables, t)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"iterate schema conflicts: %w\", err)\n\t}\n\treturn tables, nil\n}\n\n// constraintViolationCounts lists the tables carrying outstanding constraint\n// violations. mergesettle.go repairs the FK-cascade class on the auto path;\n// anything it declined lands here, blocking the commit.\nfunc constraintViolationCounts(ctx context.Context, db DBConn) ([]storage.ConstraintViolation, error) {\n\trows, err := db.QueryContext(ctx,\n\t\t\"SELECT `table`, num_violations FROM dolt_constraint_violations WHERE num_violations > 0\")\n\tif err != nil {\n\t\tif isMissingSystemTable(err) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"query constraint violations: %w\", err)\n\t}\n\tdefer func() { _ = rows.Close() }()\n\tvar out []storage.ConstraintViolation\n\tfor rows.Next() {\n\t\tvar v storage.ConstraintViolation\n\t\tif err := rows.Scan(&v.Table, &v.Count); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan constraint violation: %w\", err)\n\t\t}\n\t\tout = append(out, v)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"iterate constraint violations: %w\", err)\n\t}\n\treturn out, nil\n}\n\n// isMissingSystemTable reports whether err is dolt/MySQL's \"table does not\n// exist\". Matched on the message because the embedded engine and the MySQL","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/conflicts.go#L507-L543","documentation":"constraintViolationCounts reads dolt_constraint_violations for tables with num_violations > 0; this error wraps any query failure that is not the table being absent (missing table is treated as 'no violations'). It means the merge-blocker diagnostic could not read foreign-key/constraint violation state.","triggerScenarios":"GetMergeBlockers querying dolt_constraint_violations and receiving a non-missing-table SQL error: connectivity failure, permission denial, engine error while the merge is open, or a dolt version where the table exists but with a different schema (no table/num_violations columns).","commonSituations":"dolt version drift between the embedded engine's expectations and the actual database; restricted privileges on dolt_* tables in sql-server mode; transient disconnects while diagnosing a stalled merge.","solutions":["Fix the wrapped cause: restore connectivity or grant SELECT on dolt_constraint_violations to the user.","If the error mentions unknown columns, align the dolt engine version with what bd expects.","Retry the blocker check after the merge state stabilizes; mid-merge engine errors are often transient.","Inspect violations directly (SELECT * FROM dolt_constraint_violations WHERE num_violations > 0), repair the FK issues, then conclude the merge."],"exampleFix":"// before: hard-failing the command on a diagnosis query\nv, err := ops.GetMergeBlockers(ctx, db)\nif err != nil { return err }\n// after: log partial errors and still repair readable tables\nv, err := ops.GetMergeBlockers(ctx, db)\nif err != nil { log.Printf(\"some blockers unreadable: %v\", err) }\nfor _, cv := range v.ConstraintViolations { repairFK(ctx, cv.Table) }","handlingStrategy":"try-catch","validationCode":"// Verify the violations table is readable before the full check:\nrows, err := db.QueryContext(ctx, \"SELECT `table`, num_violations FROM dolt_constraint_violations WHERE num_violations > 0\")\nif err != nil && !missingTable(err) { /* fix access/version first */ }","typeGuard":null,"tryCatchPattern":"blockers, err := ops.GetMergeBlockers(ctx, db)\nif err != nil {\n  if strings.Contains(err.Error(), \"query constraint violations\") {\n    log.Printf(\"violations unreadable: %v — continuing with partial blockers\", err)\n  } else { return err }\n}","preventionTips":["Grant SELECT on dolt_constraint_violations to the application user.","Match the dolt engine version to bd's expected schema.","Repair FK violations promptly (mergesettle auto-path) so the table stays small."],"tags":["dolt","constraint-violations","foreign-keys","system-table"],"backgroundTag":"dolt-system-table-unavailable","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}