elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

Fix MongoDB serialization exception for FlowScope backward compatibility

Open Copilot opened this issue 8 months ago • 1 comments

Problem

MongoDB serialization fails when upgrading from Elsa 3.3.5 to 3.4.0 because the FlowScope class structure changed between versions. The old version had an OwnerActivityId property that was removed in 3.4.0, causing MongoDB to throw serialization exceptions when trying to deserialize existing workflow instances:

System.FormatException: Element 'OwnerActivityId' does not match any field or property of class Elsa.Workflows.Activities.Flowchart.Models.FlowScope.

Solution

Added the missing OwnerActivityId property back to the FlowScope class with appropriate attributes to maintain backward compatibility:

[Obsolete("This property is maintained for backward compatibility only. Do not use in new code.")]
[JsonIgnore]
public string? OwnerActivityId { get; set; }

This approach:

  • ✅ Allows MongoDB to successfully deserialize old workflow instances
  • ✅ Prevents the property from appearing in JSON serialization ([JsonIgnore])
  • ✅ Discourages use in new code ([Obsolete])
  • ✅ Follows existing patterns in the codebase (similar to ObsoleteConnection)
  • ✅ Requires minimal changes (8 lines added)

Testing

Added comprehensive unit tests to verify:

  • The property exists and can be set/get for backward compatibility
  • It's properly ignored in JSON serialization
  • FlowScope can still be deserialized without the property

Fixes #6729.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: dotnet build --no-restore --configuration Release src/modules/Elsa.Workflows.Core (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


This change is Reviewable

Copilot avatar Jun 12 '25 08:06 Copilot