Skip to content

Commit c7ca8db

Browse files
[Cherrypick][Port] Cultural Invariant Conversion of datatypes during mutation (#2316)
## Port Metadata - porting from `main` to `release/1.2` - Issue: #2284 - PR: #2307 ## Why make this change? It addresses #2284 bug raised by the customer. ~~**Note:** Made change in`src/Core/Resolvers/SqlMutationEngine.cs` just for consistency.~~ [SL: this was in original PR, but is not accurate, since no changes to SqlMutationEngine.cs are included ## What is this change? Made sure datatype conversion is `CultureInfo.InvariantCulture` Co-authored-by: Sourabh Jain <sourabhjain@microsoft.com>
1 parent 58cf603 commit c7ca8db

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/Core/Services/TypeHelper.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Data;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Globalization;
67
using System.Net;
78
using Azure.DataApiBuilder.Core.Services.OpenAPI;
89
using Azure.DataApiBuilder.Service.Exceptions;
@@ -304,12 +305,12 @@ public static bool TryGetDbTypeFromSqlDbDateTimeType(SqlDbType sqlDbType, [NotNu
304305
SyntaxKind valueKind = node.Kind;
305306
return valueKind switch
306307
{
307-
SyntaxKind.IntValue => Convert.ToInt32(node.Value), // spec
308-
SyntaxKind.FloatValue => Convert.ToDouble(node.Value), // spec
308+
SyntaxKind.IntValue => Convert.ToInt32(node.Value, CultureInfo.InvariantCulture), // spec
309+
SyntaxKind.FloatValue => Convert.ToDouble(node.Value, CultureInfo.InvariantCulture), // spec
309310
SyntaxKind.BooleanValue => Convert.ToBoolean(node.Value), // spec
310-
SyntaxKind.StringValue => Convert.ToString(node.Value), // spec
311+
SyntaxKind.StringValue => Convert.ToString(node.Value, CultureInfo.InvariantCulture), // spec
311312
SyntaxKind.NullValue => null, // spec
312-
_ => Convert.ToString(node.Value)
313+
_ => Convert.ToString(node.Value, CultureInfo.InvariantCulture)
313314
};
314315
}
315316

src/Service.Tests/CosmosTests/MutationTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using System.IO;
78
using System.Net.Http;
89
using System.Text.Json;
@@ -1074,6 +1075,31 @@ public async Task CanPatchMoreThan10AttributesInAnItemWithVariables()
10741075
Assert.AreEqual(patchResponse.GetProperty("moons").ToString(), JsonSerializer.Serialize(update.moons));
10751076
}
10761077

1078+
[TestMethod]
1079+
[DataRow("en-US")]
1080+
[DataRow("en-DE")]
1081+
public async Task CanCreateItemWithCultureInvariant(string cultureInfo)
1082+
{
1083+
CultureInfo ci = new(cultureInfo);
1084+
CultureInfo.DefaultThreadCurrentCulture = ci;
1085+
1086+
// Run mutation Add planet;
1087+
string id = Guid.NewGuid().ToString();
1088+
const string name = "test_name";
1089+
string mutation = $@"
1090+
mutation {{
1091+
createPlanet (item: {{ id: ""{id}"", name: ""{name}"", age: 10.15 }}) {{
1092+
id
1093+
name
1094+
age
1095+
}}
1096+
}}";
1097+
JsonElement response = await ExecuteGraphQLRequestAsync("createPlanet", mutation, variables: new());
1098+
1099+
// Validate results
1100+
Assert.AreEqual(Convert.ToDouble(10.15, CultureInfo.InvariantCulture), response.GetProperty("age").GetDouble());
1101+
}
1102+
10771103
/// <summary>
10781104
/// Runs once after all tests in this class are executed
10791105
/// </summary>

src/Service.Tests/CosmosTests/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Planet @model(name:""PlanetAlias"") {
4646
id : ID!,
4747
name : String,
4848
character: Character,
49-
age : Int,
49+
age : Float,
5050
dimension : String,
5151
earth: Earth,
5252
tags: [String!],

0 commit comments

Comments
 (0)