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

ReadMany fails with id/pk with ' character #3731

Closed
ealsur opened this issue Mar 1, 2023 · 0 comments · Fixed by #3732
Closed

ReadMany fails with id/pk with ' character #3731

ealsur opened this issue Mar 1, 2023 · 0 comments · Fixed by #3732
Assignees
Labels
bug Something isn't working

Comments

@ealsur
Copy link
Member

ealsur commented Mar 1, 2023

When the input of ReadMany includes values with ', the query parsing fails with:

(Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: ; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: ; Reason: ({"errors":[{"severity":"Error","location":{"start":37,"end":41},"code":"SC1001","message":"Syntax error, incorrect syntax near 'user'."}]}););)
  ----> Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: ; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: ; Reason: ({"errors":[{"severity":"Error","location":{"start":37,"end":41},"code":"SC1001","message":"Syntax error, incorrect syntax near 'user'."}]}););
  ----> Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException : {"errors":[{"severity":"Error","location":{"start":37,"end":41},"code":"SC1001","message":"Syntax error, incorrect syntax near 'user'."}]}

Repro

Create a container with /id as Partition Key Path. Then:

CosmosClient client = new CosmosClient("<connection string>");

            Container container = client.GetContainer("myDb", "container");

            string id = "the'user@test.com";

            IReadOnlyList<(string, Cosmos.PartitionKey)> partitionKeyValues = new List<(string, Cosmos.PartitionKey)>()
            {
                (id, new Cosmos.PartitionKey(id))
            };

            FeedResponse<dynamic> response = await container.ReadManyItemsAsync<dynamic>(partitionKeyValues);

The query that gets generated is:

{"query":"SELECT * FROM c WHERE c.id IN ( 'the'user@test.com' )"}

The problem is that for this case (/id being the Partition Key Definition), we use:

https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/ReadManyQueryHelper.cs#L252-L261

When the container does not have /id as the Partition Key Definition, then we use SqlParameter:

https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/ReadManyQueryHelper.cs#L276-L278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant