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

Should CosmosLinqQuery.ToString() return a relative or absolute URI for a null/empty query? #4452

Open
suhjason opened this issue Apr 24, 2024 · 0 comments
Assignees
Labels

Comments

@suhjason
Copy link

suhjason commented Apr 24, 2024

Describe the bug
CosmosLinqQuery.ToString() returns the relative Uri of the queried container if the CosmosLinqQuery expression is an empty query. For instance, when getting the queryable object from container.GetItemLinqQueryable().

In V2 SDK, DocumentQuery.ToString() returns the absolute Uri of the queried container/collection.

To Reproduce
Sample V3 code:

Container container = this.CosmosClient.GetContainer(this.databaseId, this.containerId);
IQueryable<T> queryable = container.GetItemLinqQueryable<T>();
string queryableString = queryable.ToString();

Expected behavior
In V2 similar code, the queryable.ToString() returns an absolute Uri of the container/collection:

IQueryable<T> queryable = documentClient.CreateDocumentQuery<T>(documentCollectionUri);
string queryableString = queryable.ToString();

"https://[host]:[port]/dbs/databaseName/colls/collectionName"

Actual behavior
In V3 code, queryableString returns:
"dbs/databaseName/colls/collectionName"

Environment summary
SDK Version: Latest
OS Version (e.g. Windows, Linux, MacOSX): Windows

Additional context
In the rare case where an app checks if the "empty" queryable object's string is an absolute Uri before performing specific actions, it could behave differently when migrating to V3 and the string returns a relative Uri. Sample:

if (Uri.TryCreate(queryableString, UriKind.Absolute, out Uri uri))
{
    // run specific actions
}

For my V3 migrated service, I was able to resolve and maintain the behavior by simply checking if the Uri is UriKind.RelativeOrAbsolute instead of UriKind.Absolute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants