{"record":{"id":"7803c0ade9967689","repo":"OrchardCMS/OrchardCore","slug":"the-updatecontenttask-can-t-update-the-content-item-as-it-is-7803c0","errorCode":null,"errorMessage":"The 'UpdateContentTask' can't update the content item as it is executed inline from a 'ContentDraftSavedEvent' 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 'ContentDraftSavedEvent' 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":88,"sourceCode":"        => 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        }\n\n        if (contentItem == null)\n        {\n            throw new InvalidOperationException($\"The '{nameof(UpdateContentTask)}' failed to retrieve the content item.\");\n        }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs#L70-L106","documentation":"Companion guard to the published-event case: when the task runs inline within a ContentDraftSavedEvent of the same content item, saving a draft update would re-trigger the same event in an endless loop. InvalidOperationException is thrown to break the cycle.","triggerScenarios":"InlineEvent.Name == 'ContentDraftSavedEvent' and InlineEvent.ContentItemId equals the activity's evaluated contentItemId.","commonSituations":"Workflow: ContentDraftSavedEvent -> UpdateContentTask targeting the same item; each draft save re-fires the event.","solutions":["Use an event that triggers earlier in the lifecycle, or a different content item as the update target.","Filter the event's content type so it does not include the updated type, or add an ID condition.","Perform the mutation before the save completes (e.g. a content handler) instead of via workflow.","Trigger a separate workflow execution rather than running inline."],"exampleFix":"// before\nWorkflow start: ContentDraftSavedEvent -> UpdateContentTask (same item)\n// after\nWorkflow start: ContentUpdatedEvent (non-starting) or update different item","handlingStrategy":"validation","validationCode":"if (inlineEvent?.Name == nameof(ContentDraftSavedEvent) && string.Equals(inlineEvent.ContentItemId, targetId, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"UpdateContentTask would re-enter ContentDraftSavedEvent for the same item.\");","typeGuard":null,"tryCatchPattern":"try { await task.ExecuteAsync(workflowContext, activityContext); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ContentDraftSavedEvent\"))\n{\n    logger.LogWarning(ex, \"Inline update-after-draft-save loop prevented.\");\n}","preventionTips":["Avoid UpdateContentTask (same item) directly after ContentDraftSavedEvent.","Choose earlier-lifecycle events or update a different item.","Add an ID-equality condition as a loop breaker.","Use content handlers for pre-save mutations instead of workflows."],"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"}