{"record":{"id":"921e9deb2a3aa323","repo":"OrchardCMS/OrchardCore","slug":"the-updatecontenttask-can-t-update-the-content-item-as-it-is","errorCode":null,"errorMessage":"The 'UpdateContentTask' can't update the content item as it is executed inline from a 'ContentPublishedEvent' of the same content item, please use an event that is triggered earlier.","messagePattern":"The 'UpdateContentTask' can't update the content item as it is executed inline from a 'ContentPublishedEvent' of the same content item, please use an event that is triggered earlier\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs","lineNumber":83,"sourceCode":"\n        set => SetProperty(value);\n    }\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Done\"], S[\"Failed\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var contentItemId = (await GetContentItemIdAsync(workflowContext))\n            ?? throw new InvalidOperationException($\"The {nameof(UpdateContentTask)} failed to evaluate the 'ContentItemId'.\");\n\n        var inlineEventOfSameContentItemId = string.Equals(InlineEvent.ContentItemId, contentItemId, StringComparison.OrdinalIgnoreCase);\n\n        if (inlineEventOfSameContentItemId)\n        {\n            if (InlineEvent.Name == nameof(ContentPublishedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a '{nameof(ContentPublishedEvent)}' of the same content item, please use an event that is triggered earlier.\");\n            }\n\n            if (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 '{nameof(ContentDraftSavedEvent)}' of the same content item, please use an event that is triggered earlier.\");\n            }\n        }\n\n        ContentItem contentItem = null;\n\n        if (!inlineEventOfSameContentItemId)\n        {\n            contentItem = await ContentManager.GetAsync(contentItemId, VersionOptions.DraftRequired);\n        }\n        else\n        {\n            contentItem = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey)?.ContentItem;\n        }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs#L65-L101","documentation":"Inline re-entrancy guard: if UpdateContentTask runs inline within a ContentPublishedEvent of the same content item it targets, updating would republish the item and re-trigger the event indefinitely. The library throws to prevent this loop and advises using an earlier-triggering event.","triggerScenarios":"InlineEvent.Name == 'ContentPublishedEvent' and the event's ContentItemId equals the activity's evaluated contentItemId (inline execution during publish of that same item).","commonSituations":"Workflow: ContentPublishedEvent -> UpdateContentTask on the same item (e.g. setting a field on publish). The publish inside Update re-fires the event.","solutions":["Start the workflow from ContentDraftSavedEvent or another earlier event instead of ContentPublishedEvent.","Update a different content item than the one that triggered the event.","Use a 'Content Updated'-style event with a content type filter that excludes re-entrancy, or run the update via a non-inline path.","Set a loop-protection condition comparing item IDs before the task."],"exampleFix":"// before\nWorkflow start: ContentPublishedEvent -> UpdateContentTask (same item)\n// after\nWorkflow start: ContentDraftSavedEvent -> UpdateContentTask (same item)","handlingStrategy":"validation","validationCode":"if (inlineEvent?.Name == nameof(ContentPublishedEvent) && string.Equals(inlineEvent.ContentItemId, targetId, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"UpdateContentTask would re-enter ContentPublishedEvent for the same item.\");","typeGuard":null,"tryCatchPattern":"try { await task.ExecuteAsync(workflowContext, activityContext); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ContentPublishedEvent\"))\n{\n    logger.LogWarning(ex, \"Inline update-after-publish loop prevented.\");\n}","preventionTips":["Do not put UpdateContentTask (same item) directly after ContentPublishedEvent.","Use ContentDraftSavedEvent or another earlier trigger for same-item updates.","Compare event and target item IDs in a condition before updating.","Publish-changing updates belong before the publish completes (handler), not after."],"tags":["workflows","content","infinite-loop","recursion"],"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"}