Format exception when using culture and partitionKey, difference between Windows and Linux
See original GitHub issueDescribe the bug We see different behavior between running queries on Linux versus Windows, when using culture Info and partition key/cross-partition key queries.
To Reproduce
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json;
namespace ConsoleApp1;
internal class Program
{
static void Main(string[] args)
{
var client = new CosmosClientBuilder("---url---", "---key---").Build();
var container = client.GetContainer("--database--", "--container--");
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
// Retrieves data
var noCultureWithPartitionKey = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = new PartitionKey("bc7df108-4c93-4534-ba32-167d77274511") })
.Where(c => c.Area > 5.65252);
Console.WriteLine(noCultureWithPartitionKey.Count());
// Retrieves data, cross partition
var noCultureNoPk = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = null })
.Where(c => c.Area > 5.65252);
Console.WriteLine(noCultureNoPk.Count());
// Change the culture
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
// Throws error
try
{
var withCultureWithPartitionKey = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = new PartitionKey("bc7df108-4c93-4534-ba32-167d77274511") })
.Where(c => c.Area > 5.65252);
Console.WriteLine(withCultureWithPartitionKey.Count());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Same query, cross partition
var withCultureNoPk = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = null })
.Where(c => c.Area > 5.65252);
Console.WriteLine(withCultureNoPk.Count());
}
}
class QueryObject{
[JsonProperty("id")]
public string Id{ get; set; }
[JsonProperty("partitionKey")]
public string PartitionKey { get; set; }
[JsonProperty("area")]
public double Area{ get; set; }
}
Results on Windows:
10
240193
10
240193
Results on Linux:
10
240193
Input string was not in a correct format.
240193
Expected behavior Same behavior when running on Windows/Linux/Docker, independent on the thread culture.
Actual behavior We are running a docker container with an webapi which uses request localization based on the accept language header. Customers from Norway, France are running into problems, because of the “Input string was not in a correct format.” exception (all our queries are on a specific partition key).
Environment summary SDK Version: 2.32.3 OS Version Windows vs Linux (Ubuntu) vs Official Docker images
Additional context Add any other context about the problem here (for example, complete stack traces or logs).
Issue Analytics
- State:
- Created 6 months ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
This looks like the correct diagnosis. I’ll get this issue assigned. Thanks @mlankamp
I can provide a PR (and unit-test also ) if you want