elsa-workflows / elsa-workflows/elsa-core

Issue with custom activity related to mongoDB persistence provider

Open
#4,936 3 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

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](https://github.com/elsa-workflows/elsa-core/assets/19525088/74bb0aca-125f-47e3-b7c7-45d1f9edec27)

Error Stack: MongoDB.Driver.MongoBulkWriteException`1[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.MongoCollectionImpl`1.BulkWriteAsync(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
at Elsa.MongoDb.Common.MongoDbStore`1.SaveManyAsync(IEnumerable`1 documents, CancellationToken cancellationToken)
at Elsa.MongoDb.Modules.Runtime.MongoWorkflowExecutionLogStore.SaveManyAsync(IEnumerable`1 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.Endpoint`2.ExecAsync(CancellationToken ct)
at FastEndpoints.Endpoint`2.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](https://github.com/elsa-workflows/elsa-core/assets/19525088/f480de37-480b-444c-8ce2-cf6feeaf9772)

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);
}
}
}

Contributor guide

Open the contributing guide

Research direction

Start with the custom-activities documentation and reproduce the failure by calling the custom Welcome activity through Postman. Trace the MongoDB persistence path named in the stack, especially MongoDbStore.SaveManyAsync and WorkflowExecutionLogStore.SaveManyAsync, to determine why ActivityState.WelComeNote contains the invalid $type field. Done means the activity executes and its workflow state persists without the MongoDB bulk-write error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, mongodb
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.