Azure / Azurite

A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
MIT License
1.8k stars 320 forks source link

Query on table with empty partition keys doesn't return any result after upgrade to 3.25.0 #2078

Open mariusz-rubin opened 1 year ago

mariusz-rubin commented 1 year ago

Which service(blob, file, queue, table) does this issue concern?

Table

Which version of the Azurite was used?

3.25.0

Where do you get Azurite? (npm, DockerHub, NuGet, Visual Studio Code Extension)

npm

What's the Node.js version?

20.2.0

What problem was encountered?

Executing QueryAsync on TableClient doesn't return the expected entity when PartitionKey is set to an empty string. This works with the previous Azurite version 3.24.0. Using Nuget package Azure.Data.Tables in version 12.8.0

Steps to reproduce the issue?

The C# code below is inserting an entity with empty PartitionKey. Getting the entity by PartitionKey and RowKey works but filtering with QueryAsync by a text property doesn't return any result.

using Azure;
using Azure.Data.Tables;

var tableClient = new TableClient(
    connectionString: "UseDevelopmentStorage=true",
    tableName: "Test");

await tableClient.CreateIfNotExistsAsync();

try
{
    const string textValue = "Test value";

    var entity = new Entity
    {
        PartitionKey = string.Empty,
        RowKey = Guid.NewGuid().ToString(),
        Text = textValue
    };

    await tableClient.AddEntityAsync(entity);

    var gotEntity = await tableClient.GetEntityIfExistsAsync<Entity>(entity.PartitionKey, entity.RowKey);
    Console.WriteLine($"Got entity: '{gotEntity.HasValue}'");

    var foundEntities = await tableClient.QueryAsync<Entity>(x => x.Text == textValue).ToListAsync();
    Console.WriteLine($"Found entity: '{foundEntities.Any()}'");
}
finally
{
    await tableClient.DeleteAsync();
}

class Entity : ITableEntity
{
    public string PartitionKey { get; set; } = string.Empty;
    public string RowKey { get; set; } = string.Empty;
    public string Text { get; set; } = string.Empty;
    public DateTimeOffset? Timestamp { get; set; }
    public ETag ETag { get; set; }
}

Referenced packages:

 <ItemGroup>
    <PackageReference Include="Azure.Data.Tables" Version="12.8.0" />
    <PackageReference Include="System.Linq.Async" Version="6.0.1" />
  </ItemGroup>

Have you found a mitigation/solution?

Using the previous Azurite version 3.24.0.

garrettbaski commented 1 year ago

I created PR #2079 to address this. It looks like we were doing !!.PartitionKey to check if this was an entity or not. JS evaluates empty string to false so this failed and then we thought it was not an entity and took the wrong code path.

garrettbaski commented 1 year ago

A 3.25.1 hotfix version was released and should solve the issue. Please let me know if it doesn't.