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

Container Iterators' ReadNextAsync return inconsistent HttpStatusCodes #625

Closed
pavelsimeonov opened this issue Aug 2, 2019 · 2 comments · Fixed by #626
Closed

Container Iterators' ReadNextAsync return inconsistent HttpStatusCodes #625

pavelsimeonov opened this issue Aug 2, 2019 · 2 comments · Fixed by #626
Assignees
Labels
bug Something isn't working QUERY

Comments

@pavelsimeonov
Copy link

Describe the bug
I have a Microsoft.Azure.Cosmos.Container instance where I'm using GetItemQueryIterator<T> to get an iterator, then I do await iterator.ReadNextAsync() - if I give the iterator any valid sql query, the response's StatusCode property value is 0 but I do get my data. If I don't give the iterator a sql query (leave the parameter to be null) the StatusCode is 202 Accepted and I get the expected data. If I use GetItemQueryStreamIterator instead, with a valid sql query, I get StatusCode 200 OK.

To Reproduce

        //query has been simplified for testing purposes - I confirmed the issue is present with this query. The value of "_container.Id" is the name of my collection in CosmosDb.
        QueryDefinition sqlQuery = new QueryDefinition($"select * from {_container.Id}");

        //QueryStreamIterator implementation start --- Using a stream iterator works fine
        var streamIterator = _container.GetItemQueryStreamIterator(sqlQuery, continuationToken,
            new QueryRequestOptions()
            {
                MaxItemCount = maxItems
            });

        while (streamIterator.HasMoreResults)
        {
            var results = await streamIterator.ReadNextAsync();
            //At this point results.StatusCode is 200 OK
            Stream stream = results.Content;
            using (var reader = new StreamReader(stream))
            {
                //all expected data is received.
                string data = await reader.ReadToEndAsync();
            }
        }
        //QueryStreamIterator implementation end --- 

        //QueryIterator implementation start --- 
        var iterator = _container.GetItemQueryIterator<T>(sqlQuery, continuationToken,
            new QueryRequestOptions()
            {
                MaxItemCount = maxItems
            });

        var result = await iterator.ReadNextAsync();
        //Here result.StatusCode is 0, but I do get my data. If I make "sqlQuery" null - here I get StatusCode 202 Accepted.
        if (result.StatusCode == HttpStatusCode.Accepted)
        {
            return new ExportResult<T>
            {
                HasMore = iterator.HasMoreResults, //this is "true", as expected
                Items = result.Resource.ToList(), //my data is received as expected
                ContinuationToken = result.ContinuationToken //this is populated and works as expected when provided on subsequent call
            };
        }

Expected behavior
To not receive StatusCode 0 when I actually got my data in the response. Also, why when using GetItemQueryStreamIterator's ReadNextAsync the response's StatusCode is 200 OK but when using GetItemQueryIterator<T> with a null query string parameter value the response's StatusCode is 202 Accepted? I'd expect both of them to be 200 OK.

Environment summary
SDK Version: first observed in v3.0, issue persists in v3.1.0
OS Version: Windows 10

@j82w
Copy link
Contributor

j82w commented Aug 2, 2019

The status code being 0 is a bug, and I have a repo.

@j82w
Copy link
Contributor

j82w commented Aug 2, 2019

The status codes being different is also caused by a similar bug. I have a fix for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working QUERY
Projects
None yet
2 participants