Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RawInput to workaround double-serialization issue #966

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/DurableTask.Core/Serializing/DataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace DurableTask.Core.Serializing
{
using System;
using DurableTask.Core.Serializing.Internal;

/// <summary>
/// Abstract class for serializing and deserializing data
Expand Down Expand Up @@ -59,5 +60,17 @@ public T Deserialize<T>(string data)

return (T)result;
}

internal string SerializeInternal(object value)
{
#pragma warning disable CS0618 // Type or member is obsolete. Intentional internal usage.
if (value is RawInput raw)
{
return raw.Value;
}
#pragma warning restore CS0618 // Type or member is obsolete

return this.Serialize(value);
}
}
}
42 changes: 42 additions & 0 deletions src/DurableTask.Core/Serializing/Internal/RawInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

#nullable enable
using System;

namespace DurableTask.Core.Serializing.Internal
{
/// <summary>
/// This is an internal API that supports the DurableTask infrastructure and not subject to the same compatibility
/// standards as public APIs. It may be changed or removed without notice in any release. You should only use it
/// directly in your code with extreme caution and knowing that doing so can result in application failures when
/// updating to a new DurableTask release.
/// </summary>
[Obsolete("Not for public consumption.")]
public sealed class RawInput
{
/// <summary>
/// Initializes a new instance of the <see cref="RawInput" /> class.
/// </summary>
/// <param name="value">The raw input value to use.</param>
public RawInput(string? value)
{
this.Value = value;
}

/// <summary>
/// Gets the raw input value.
/// </summary>
public string? Value { get; }
}
}
6 changes: 3 additions & 3 deletions src/DurableTask.Core/TaskHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ async Task<OrchestrationInstance> InternalCreateOrchestrationInstanceWithRaisedE
ExecutionId = Guid.NewGuid().ToString("N"),
};

string serializedOrchestrationData = this.defaultConverter.Serialize(orchestrationInput);
string serializedOrchestrationData = this.defaultConverter.SerializeInternal(orchestrationInput);
var startedEvent = new ExecutionStartedEvent(-1, serializedOrchestrationData)
{
Tags = orchestrationTags,
Expand Down Expand Up @@ -626,7 +626,7 @@ async Task<OrchestrationInstance> InternalCreateOrchestrationInstanceWithRaisedE

if (eventData != null)
{
string serializedEventData = this.defaultConverter.Serialize(eventData);
string serializedEventData = this.defaultConverter.SerializeInternal(eventData);
var eventRaisedEvent = new EventRaisedEvent(-1, serializedEventData) { Name = eventName };

this.logHelper.RaisingEvent(orchestrationInstance, eventRaisedEvent);
Expand Down Expand Up @@ -694,7 +694,7 @@ public async Task RaiseEventAsync(OrchestrationInstance orchestrationInstance, s
throw new ArgumentException(nameof(orchestrationInstance));
}

string serializedInput = this.defaultConverter.Serialize(eventData);
string serializedInput = this.defaultConverter.SerializeInternal(eventData);

// Distributed Tracing
EventRaisedEvent eventRaisedEvent = new EventRaisedEvent(-1, serializedInput) { Name = eventName };
Expand Down