portainer/portainer · error

unable to persist environment relation in database: %w

Error message

unable to persist environment relation in database: %w

What it means

Error "unable to persist environment relation in database: %w" thrown in portainer/portainer.

Source

Thrown at api/internal/edge/edgestacks/service.go:91

// PersistEdgeStack persists the edge stack in the database and its relations
func (service *Service) PersistEdgeStack(
	tx dataservices.DataStoreTx,
	stack *portainer.EdgeStack,
	storeManifest edgetypes.StoreManifestFunc) (*portainer.EdgeStack, error) {

	relationConfig, err := edge.FetchEndpointRelationsConfig(tx)
	if err != nil {
		return nil, fmt.Errorf("unable to find environment relations in database: %w", err)
	}

	relatedEndpointIds, err := edge.EdgeStackRelatedEndpoints(stack.EdgeGroups, relationConfig.Endpoints, relationConfig.EndpointGroups, relationConfig.EdgeGroups)
	if err != nil {
		if errors.Is(err, edge.ErrEdgeGroupNotFound) {
			return nil, httperrors.NewInvalidPayloadError(err.Error())
		}

		return nil, fmt.Errorf("unable to persist environment relation in database: %w", err)
	}

	stackFolder := strconv.Itoa(int(stack.ID))
	composePath, manifestPath, projectPath, err := storeManifest(stackFolder, relatedEndpointIds)
	if err != nil {
		return nil, fmt.Errorf("unable to store manifest: %w", err)
	}

	stack.ManifestPath = manifestPath
	stack.ProjectPath = projectPath
	stack.EntryPoint = composePath

	if err := tx.EdgeStack().Create(stack.ID, stack); err != nil {
		return nil, err
	}

	for _, endpointID := range relatedEndpointIds {
		status := &portainer.EdgeStackStatusForEnv{EndpointID: endpointID}

View on GitHub (pinned to 17e74456ff)

When it happens

Trigger: Thrown at api/internal/edge/edgestacks/service.go:91 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of portainer/portainer@17e74456ff (2026-08-26). Data as JSON: /api/errors/17b1f894753f0f1c. Report an issue: GitHub.