{"record":{"id":"17b1f894753f0f1c","repo":"portainer/portainer","slug":"unable-to-persist-environment-relation-in-database","errorCode":null,"errorMessage":"unable to persist environment relation in database: %w","messagePattern":"unable to persist environment relation in database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/internal/edge/edgestacks/service.go","lineNumber":91,"sourceCode":"\n// PersistEdgeStack persists the edge stack in the database and its relations\nfunc (service *Service) PersistEdgeStack(\n\ttx dataservices.DataStoreTx,\n\tstack *portainer.EdgeStack,\n\tstoreManifest edgetypes.StoreManifestFunc) (*portainer.EdgeStack, error) {\n\n\trelationConfig, err := edge.FetchEndpointRelationsConfig(tx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to find environment relations in database: %w\", err)\n\t}\n\n\trelatedEndpointIds, err := edge.EdgeStackRelatedEndpoints(stack.EdgeGroups, relationConfig.Endpoints, relationConfig.EndpointGroups, relationConfig.EdgeGroups)\n\tif err != nil {\n\t\tif errors.Is(err, edge.ErrEdgeGroupNotFound) {\n\t\t\treturn nil, httperrors.NewInvalidPayloadError(err.Error())\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"unable to persist environment relation in database: %w\", err)\n\t}\n\n\tstackFolder := strconv.Itoa(int(stack.ID))\n\tcomposePath, manifestPath, projectPath, err := storeManifest(stackFolder, relatedEndpointIds)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to store manifest: %w\", err)\n\t}\n\n\tstack.ManifestPath = manifestPath\n\tstack.ProjectPath = projectPath\n\tstack.EntryPoint = composePath\n\n\tif err := tx.EdgeStack().Create(stack.ID, stack); err != nil {\n\t\treturn nil, err\n\t}\n\n\tfor _, endpointID := range relatedEndpointIds {\n\t\tstatus := &portainer.EdgeStackStatusForEnv{EndpointID: endpointID}","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/portainer/portainer/blob/17e74456ff6e794b9d5439ec3fa06922aa18a3f8/api/internal/edge/edgestacks/service.go#L73-L109","documentation":"Error \"unable to persist environment relation in database: %w\" thrown in portainer/portainer.","triggerScenarios":"Thrown at api/internal/edge/edgestacks/service.go:91 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"17e74456ff6e794b9d5439ec3fa06922aa18a3f8","analyzedAt":"2026-08-26T23:09:01.915Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}