elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.05k stars 1.1k forks source link

Issue with custom activity related to mongoDB persistence provider #4936

Open chiragp9 opened 4 months ago

chiragp9 commented 4 months ago

I created a custom activity as per a below link, but I am getting an error as attached in screenshot when I call that activity from postman. https://v3.elsaworkflows.io/docs/extensibility/custom-activities

image_2024_02_13T04_08_33_239Z

Error Stack: MongoDB.Driver.MongoBulkWriteException1[Elsa.Workflows.Runtime.Entities.WorkflowExecutionLogRecord]: A bulk write operation resulted in one or more errors. WriteErrors: [ { Category : "Uncategorized", Code : 52, Message : "The dollar ($) prefixed field '$type' in 'ActivityState.WelComeNote.$type' is not valid for storage." } ]. at MongoDB.Driver.MongoCollectionImpl1.BulkWriteAsync(IClientSessionHandle session, IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSessionAsync[TResult](Func2 funcAsync, CancellationToken cancellationToken) at Elsa.MongoDb.Common.MongoDbStore1.SaveManyAsync(IEnumerable1 documents, CancellationToken cancellationToken) at Elsa.MongoDb.Modules.Runtime.MongoWorkflowExecutionLogStore.SaveManyAsync(IEnumerable1 records, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Middleware.Workflows.PersistWorkflowExecutionLogMiddleware.InvokeAsync(WorkflowExecutionContext context) at Elsa.Workflows.Runtime.Middleware.Workflows.PersistActivityExecutionLogMiddleware.InvokeAsync(WorkflowExecutionContext context) at Elsa.Workflows.Runtime.Middleware.Workflows.PersistBookmarkMiddleware.InvokeAsync(WorkflowExecutionContext context) at Elsa.Workflows.Runtime.Middleware.Workflows.PersistentVariablesMiddleware.InvokeAsync(WorkflowExecutionContext context) at Elsa.Workflows.Runtime.Middleware.Workflows.ScheduleBackgroundActivitiesMiddleware.InvokeAsync(WorkflowExecutionContext context) at Elsa.Workflows.Pipelines.WorkflowExecution.WorkflowExecutionPipeline.ExecuteAsync(WorkflowExecutionContext context) at Elsa.Workflows.Services.WorkflowRunner.RunAsync(WorkflowExecutionContext workflowExecutionContext) at Elsa.Workflows.Services.WorkflowRunner.RunAsync(Workflow workflow, RunWorkflowOptions options, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.WorkflowHost.StartWorkflowAsync(StartWorkflowHostOptions options, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.StartWorkflowAsync(IWorkflowHost workflowHost, StartWorkflowRuntimeOptions options) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.StartWorkflowAsync(IWorkflowHost workflowHost, StartWorkflowRuntimeOptions options) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.StartWorkflowAsync(String definitionId, StartWorkflowRuntimeOptions options) at Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Execute.Execute.HandleAsync(Request request, CancellationToken cancellationToken) at FastEndpoints.Endpoint2.ExecAsync(CancellationToken ct) at FastEndpoints.Endpoint2.ExecAsync(CancellationToken ct) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Elsa.Http.Middleware.WorkflowsMiddleware.InvokeAsync(HttpContext httpContext) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context) at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

HEADERS

Accept: / Connection: keep-alive Host: localhost:7237 User-Agent: PostmanRuntime/7.36.1 Accept-Encoding: gzip, deflate, br Content-Type: application/json Content-Length: 10 Postman-Token: be042bf3-303f-4a87-ba49-426a6a65ed0e

image_2024_02_13T03_53_47_036Z

Below is the code for the activity. namespace Elsa3Server { public class Welcome : CodeActivity { public Input WelComeNote { get; set; } = default!;

    protected override void Execute(ActivityExecutionContext context)
    {
        var name = WelComeNote.Get(context);
        var message = $"Hello, {name}!";
        context.SetResult(message);
    }
}

}

glime-ai[bot] commented 4 months ago

To assist you with the error you're encountering with your custom activity in Elsa Studio, I would need to see the specific error message that is displayed when you drop the activity into the studio. The screenshot you mentioned seems to be missing or not properly linked, as I cannot view it.

However, based on the code snippet you provided for your custom activity, the code appears to be correctly structured according to the documentation for creating custom activities in Elsa 3.0. If you're following the documentation correctly but still encountering an error, it could be due to several reasons such as:

  1. An issue with the Elsa Studio setup or configuration.
  2. A mismatch between the Elsa version you're using and the version covered in the documentation.
  3. A missing or incorrect registration of the custom activity in your application's startup configuration.
  4. A potential bug in Elsa Studio or the Elsa framework itself.

To further diagnose the issue, please provide the following information:

Once you provide this information, I'll be able to give you more targeted advice on how to resolve the issue.

chiragp9 commented 4 months ago

I have updated issue. Please look at it and give me resolution.