{"record":{"id":"01ad316b7202a0c2","repo":"OrchardCMS/OrchardCore","slug":"the-updatecontenttask-can-t-publish-the-content-item-as-it","errorCode":null,"errorMessage":"The 'UpdateContentTask' can't publish the content item as it is executed inline from a starting 'ContentPublishedEvent' of the same content type, which would result in an infinitive loop.","messagePattern":"The 'UpdateContentTask' can't publish the content item as it is executed inline from a starting 'ContentPublishedEvent' of the same content type, which would result in an infinitive loop\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs","lineNumber":117,"sourceCode":"        {\n            contentItem = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey)?.ContentItem;\n        }\n\n        if (contentItem == null)\n        {\n            throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' failed to retrieve the content item.\");\n        }\n\n        if (!inlineEventOfSameContentItemId && InlineEvent.IsStart && InlineEvent.ContentType == contentItem.ContentType)\n        {\n            if (InlineEvent.Name == nameof(ContentUpdatedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentUpdatedEvent)}' of the same content type, which would result in an infinitive loop.\");\n            }\n\n            if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' can't publish the content item as it is executed inline from a starting '{nameof(ContentPublishedEvent)}' of the same content type, which would result in an infinitive loop.\");\n            }\n\n            if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentDraftSavedEvent)}' of the same content type, which would result in an infinitive loop.\");\n            }\n        }\n\n        if (!string.IsNullOrWhiteSpace(ContentProperties.Expression))\n        {\n            var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);\n            contentItem.Merge(JsonNode.Parse(contentProperties), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace });\n        }\n\n        if (!inlineEventOfSameContentItemId)\n        {\n            await ContentManager.UpdateAsync(contentItem);\n        }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs#L99-L135","documentation":"UpdateContentTask refuses to publish a content item when it is executed inline from a ContentPublishedEvent workflow started for the same content type. Re-publishing inside the publish event would re-trigger the same workflow, producing an infinite loop. The guard throws InvalidOperationException before any content is modified.","triggerScenarios":"A workflow starts with a ContentPublishedEvent activity for a content type, and the workflow's UpdateContentTask has Publish=true; the task runs inline during the same publish request and tries to publish the item again.","commonSituations":"Developer builds an automation that 'touches' content on publish (e.g. updating a date or computed field) and leaves the Publish checkbox enabled on the UpdateContentTask, not realizing publishing re-enters the same workflow.","solutions":["Uncheck Publish on the UpdateContentTask so it saves a draft instead of re-publishing.","Remove the ContentPublishedEvent start activity or scope it to a different content type.","Set the inline event's content type filter so the workflow does not match the type being updated.","Use a non-inline trigger (e.g. a scheduled/background workflow) if the re-publish is genuinely required."],"exampleFix":"// before: UpdateContentTask with Publish = true inside a ContentPublishedEvent workflow\n// after\n// In the workflow editor set UpdateContentTask.Publish = false (save draft only),\n// or start the workflow from ContentDraftSavedEvent with Publish = true instead.","handlingStrategy":"validation","validationCode":"// In the workflow editor, before enabling:\nbool wouldLoop = task.Publish && inlineEvent.Name == nameof(ContentPublishedEvent);\nif (wouldLoop) throw new InvalidOperationException(\"Set Publish=false or change the start event.\");","typeGuard":null,"tryCatchPattern":"try { await workflowManager.RunWorkflowAsync(...); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"UpdateContentTask\")) { logger.LogWarning(ex, \"Inline publish loop blocked\"); }","preventionTips":["Never leave Publish=true on UpdateContentTask inside a ContentPublishedEvent workflow.","Prefer saving drafts for updates triggered by publish events.","Review workflow definitions after upgrades to Orchard Core versions that added these loop guards."],"tags":["workflows","infinite-loop","content"],"backgroundTag":"invalid-state-transition","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}