Preserve metadata for unknown activities (#7323)

* Extract and copy metadata when activity type is not found in `ActivityJsonConverter`.

* Improve `ActivityJsonConverter`: Correct metadata extraction to read from NotFoundActivity wrapper.

* Reposition activity description and display text assignment to follow metadata extraction in `ActivityJsonConverter`.

* Update src/modules/Elsa.Workflows.Core/Serialization/Converters/ActivityJsonConverter.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sipke Schoorstra 2026-02-25 20:03:04 +01:00 committed by GitHub
parent 5816f6e3be
commit 7e2829ddcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,8 +52,24 @@ public class ActivityJsonConverter(
notFoundActivity.MissingTypeName = activityTypeName;
notFoundActivity.MissingTypeVersion = activityTypeVersion;
notFoundActivity.OriginalActivityJson = activityRoot.ToString();
// Extract metadata from doc.RootElement rather than activityRoot.
// In round-trip scenarios, activityRoot may have been reassigned to the inner originalActivityJson (see line 37),
// but we want the metadata from the current activity being deserialized, which represents the NotFoundActivity
// placeholder's position and annotations in the designer.
if (doc.RootElement.TryGetProperty("metadata", out var outerMetadataElement))
{
var outerMetadata = JsonSerializer.Deserialize<IDictionary<string, object>>(outerMetadataElement.GetRawText(), clonedOptions);
if (outerMetadata != null)
{
notFoundActivity.Metadata = outerMetadata;
}
}
// Set display text and description after metadata assignment to ensure they always reflect the current state
notFoundActivity.SetDisplayText($"Not Found: {activityTypeName}");
notFoundActivity.SetDescription($"Could not find activity type {activityTypeName} with version {activityTypeVersion}");
return notFoundActivity;
}