hasura/graphql-engine · error

unable to marshal run_sql args in %s: %w

Error message

unable to marshal run_sql args in %s: %w

What it means

Thrown while running `hasura scripts update-project-v2` when converting a v1 up.yaml metadata migration. For each query of type run_sql the script marshals query.Args to YAML; if yaml.Marshal fails (essentially only for values that cannot be represented in YAML, such as NaN, -Inf, or unsupported map key types), this error wraps the marshal failure along with the offending migration filename.

Source

Thrown at cli/commands/scripts_update_config_v2.go:159

				var queries []hasuradb.HasuraInterfaceQuery

				err = yaml.Unmarshal(buf.Bytes(), &queries)
				if err != nil {
					return errors.E(
						op,
						fmt.Errorf("unable to unmarshal %s: %w", upMetaMigration.Raw, err),
					)
				}
				// for each query check if type is run_sql
				// if yes, append to bytes buffer
				for _, query := range queries {
					if query.Type == "run_sql" {
						argByt, err := yaml.Marshal(query.Args)
						if err != nil {
							return errors.E(
								op,
								fmt.Errorf(
									"unable to marshal run_sql args in %s: %w",
									upMetaMigration.Raw,
									err,
								),
							)
						}

						var to hasura.PGRunSQLInput

						err = yaml.Unmarshal(argByt, &to)
						if err != nil {
							return errors.E(
								op,
								fmt.Errorf(
									"unable to unmarshal run_sql args in %s: %w",
									upMetaMigration.Raw,
									err,
								),

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Inspect the file named in the error message and fix or remove invalid values in the run_sql args
  2. Restore the migrations directory from migrations_backup and re-run the script after fixing
  3. Regenerate the offending migration with the current CLI rather than hand-editing args
Defensive patterns

Strategy: validation

Validate before calling

// before running update-project-v2, scan migration yaml files
import (
  "os"
  "path/filepath"
  "go.yaml.in/yaml/v3"
)
func checkRunnable(dir string) error {
  return filepath.Walk(dir, func(p string, info os.FileInfo, err error) error {
    if err != nil || filepath.Ext(p) != ".yaml" { return err }
    b, rerr := os.ReadFile(p); if rerr != nil { return rerr }
    var q []map[string]any
    if uerr := yaml.Unmarshal(b, &q); uerr != nil { return uerr }
    for _, item := range q {
      if item["type"] == "run_sql" {
        if _, merr := yaml.Marshal(item["args"]); merr != nil { return merr }
      }
    }
    return nil
  })
}

Prevention

When it happens

Trigger: Executing update-project-v2 against a migrations directory whose <version>.up.yaml contains a run_sql entry whose args fail to serialize (e.g. a float NaN/Inf value or invalid map key inside args).

Common situations: Hand-edited YAML migrations with malformed arg values; migrations generated by older CLI versions or external tooling that injected non-serializable values into run_sql args.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/e16c4e0c6390ac87. Report an issue: GitHub.