Fix DynamoDB UpdateExpression syntax error in MarkEventUnprocessed method #1397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the
Amazon.DynamoDBv2.AmazonDynamoDBException: Invalid UpdateExpression: Syntax error; token: "=", near: "not_processed"
error that occurs when using AWS DynamoDB locking features.Problem
The
MarkEventUnprocessed
method inDynamoPersistenceProvider.cs
was using incorrect DynamoDB UpdateExpression syntax:The
ADD
operation in DynamoDB does not use the=
operator, causing the UpdateExpression to be invalid and throwing a syntax error during workflow execution.Solution
Corrected the UpdateExpression syntax by removing the invalid
=
operator:This follows the proper DynamoDB UpdateExpression syntax where
ADD
operations directly specify the attribute name followed by the value reference without an equals sign.Impact
UseAwsDynamoLocking
configurationCloses issue where workflows would fail with DynamoDB UpdateExpression syntax errors during event processing.
Original prompt
This section details on the original issue you should resolve
<issue_title>Amazon.DynamoDBv2.AmazonDynamoDBException: Invalid UpdateExpression: Syntax error; token: "=", near: "not_processed</issue_title>
<issue_description>Describe the bug
Sometimes during a workflow execution we see the following exception:
Amazon.DynamoDBv2.AmazonDynamoDBException: Invalid UpdateExpression: Syntax error; token: "=", near: "not_processed
To Reproduce
use the following nuget versions:
WorkflowCore 3.6.2
WorkflowCore.Providers.AWS 3.6.0
happens after i configure: UseAwsDynamoLocking in startup.cs
Expected behavior
Should start the workflow
Additional context
Logs:
{"app":"MyApp","timestamp":"2024-11-12T11:52:22.7271646Z","message":"Starting step "WaitFor" on workflow "16f21c6f-4e4c-4636-a196-8d4dfe51234c"","level":"Debug","0":"WaitFor","1":"16f21c6f-4e4c-4636-a196-8d4dfe51234c","category":"WorkflowCore.Services.WorkflowExecutor","threadId":126,"version":"0.1.0+df7b726674aae621f4a6a7b477a91afb45072a98","logVersion":"2"}
{"app":"MyApp","timestamp":"2024-11-12T11:52:23.3639000Z","message":"Subscribing to event "operationCompletedEvent" "AlisTestingLockingZ3" for workflow "16f21c6f-4e4c-4636-a196-8d4dfe51234c" step 1","level":"Debug","0":"operationCompletedEvent","1":"AlisTestingLockingZ3","2":"16f21c6f-4e4c-4636-a196-8d4dfe51234c","3":1,"category":"WorkflowCore.Services.BackgroundTasks.WorkflowConsumer","threadId":77,"version":"0.1.0+df7b726674aae621f4a6a7b477a91afb45072a98","logVersion":"2"}
and then this error is thrown:
Amazon.DynamoDBv2.AmazonDynamoDBException: Invalid UpdateExpression: Syntax error; token: "=", near: "not_processed = :n"\r\n ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.\r\n at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)\r\n at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)\r\n at Amazon.Runtime.Internal.HttpHandler
1.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n --- End of inner exception stack trace ---\r\n at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)\r\n at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)\r\n at Amazon.Runtime.Internal.ExceptionHandler
1.HandleAsync(IExecutionContext executionContext, Exception exception)\r\n at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)\r\n at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.XRay.Recorder.Handlers.AwsSdk.Internal.XRayPipelineHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)\r\n at WorkflowCore.Providers.AWS.Services.DynamoPersistenceProvider.MarkEventUnprocessed(String id, CancellationToken cancellationToken)\r\n at WorkflowCore.Services.BackgroundTasks.WorkflowConsumer.SubscribeEvent(EventSubscription subscription, IPersistenceProvider persistenceStore, CancellationToken cancellationToken)\r\n at WorkflowCore.Services.BackgroundTasks.WorkflowConsumer.SubscribeEvent(EventSubscription subscription, IPersistenceProvider persistenceStore, CancellationToken cancellationToken)\r\n at WorkflowCore.Services.BackgroundTasks.WorkflowConsumer.ProcessItem(String itemId, Cancellation...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.