{"record":{"id":"6daae5a9d37a0913","repo":"hasura/graphql-engine","slug":"applying-data-sources-failed-s","errorCode":null,"errorMessage":"applying data sources failed: %s","messagePattern":"applying data sources failed: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_apply_data_sources.go","lineNumber":145,"sourceCode":"\t}\n\n\tresp, body, err := o.EC.APIClient.V1Metadata.SendCommonMetadataOperation(\n\t\tjson.RawMessage(requestBody),\n\t)\n\tif err != nil {\n\t\treturn errors.E(op, err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tb, err := io.ReadAll(body)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, errors.KindHasuraAPI, err)\n\t\t}\n\n\t\treturn errors.E(\n\t\t\top,\n\t\t\terrors.KindHasuraAPI,\n\t\t\tfmt.Errorf(\"applying data sources failed: %s\", string(b)),\n\t\t)\n\t}\n\n\to.EC.Logger.Infof(\"Data sources applied (%d)\", numSources)\n\n\treturn nil\n}\n\n// addSourceArgs holds only the fields accepted by the server's `<kind>_add_source` metadata API.\n// Notably it excludes tables/functions/permissions so that this operation only touches the source's\n// connection configuration and never the rest of the source's metadata.\ntype addSourceArgs struct {\n\tName                 string    `yaml:\"name\"`\n\tConfiguration        yaml.Node `yaml:\"configuration\"`\n\tReplaceConfiguration bool      `yaml:\"replace_configuration\"`\n\tCustomization        yaml.Node `yaml:\"customization,omitempty\"`\n\tHealthCheck          yaml.Node `yaml:\"health_check,omitempty\"`\n}","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_apply_data_sources.go#L127-L163","documentation":"Returned by the metadata apply flow when applying data sources to the Hasura server fails. The message embeds the raw response body from the Hasura API (string(b)), so the actual server-side error (path/configuration invalid, connection to source DB failed, etc.) is included verbatim. It is tagged with errors.KindHasuraAPI, identifying it as a server API failure rather than a client-side one.","triggerScenarios":"Running `hasura metadata apply` (or code invoking this Run) with a metadata data_sources.yaml/config that the server rejects: invalid database URL, unreachable database, unsupported driver, duplicate source name, or a source configuration the server version cannot parse. The Hasura /v1/metadata or data source API returns a non-success response whose body becomes the message.","commonSituations":"Environment variables for database URLs not set when applying, database behind a firewall unreachable from the server, applying metadata exported from a newer Hasura version to an older server, or mismatched source NENO/LINEAR config keys.","solutions":["Read the embedded response body in the error — it names the failing data source and the reason (e.g. 'connection refused', 'invalid connection string')","Test connectivity from the Hasura server to each database in data_sources before applying","Verify env-var interpolation in the metadata files is resolved in the environment where apply runs","Align CLI metadata format with the server version; re-export metadata from a server of the same version and re-apply your changes on top"],"exampleFix":"# before (data_sources.yaml with unreachable DB)\ndatabases:\n- name: default\n  configuration:\n    connection_info:\n      database_url: postgres://db:5432/app\n# after — point to a reachable instance or use env var\n      database_url: ${DATABASE_URL}","handlingStrategy":"fallback","validationCode":"# Shell: verify each data source DB is reachable before apply\nfor db in default pg2; do\n  pg_isready -d \"$db\" || exit 1\ndone\nhasura metadata apply","typeGuard":null,"tryCatchPattern":"// Go: detect API-kind failures and dump the response body\nkind := errors.Kind(err)\nif kind == errors.KindHasuraAPI {\n  log.Printf(\"server rejected data sources: %v\", err)\n  // fall back to applying sources one at a time to isolate the bad one\n}","preventionTips":["Resolve env vars used in data source connection strings before apply","Test server-to-database connectivity separately","Apply data sources individually when a big metadata set fails"],"tags":["hasura-api","data-sources","metadata-apply","network"],"backgroundTag":"hasura-api-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}