PlagueHO / CosmosDB

PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
http://dscottraynsford.com
MIT License
152 stars 46 forks source link

Get-CosmosDbDocument -QueryParameters hashtable array is case sensitive #446

Open Szeraax opened 2 years ago

Szeraax commented 2 years ago

I have to do lower case name and value keys in each hashtable.

If I do upper case NAME, I get the error:

Invalid query. Specified parameterized query JSON is malformed

If I do upper case VALUE, I get no results.

Will start digging into code shortly.

Szeraax commented 2 years ago

Ok, so this cmdlet just passes through the hashtable directly as seen here: https://github.com/PlagueHO/CosmosDB/blob/7ca25c5037b72268e53cdbbb4e261b171fca5c79/source/Public/documents/Get-CosmosDbDocumentJson.ps1#L146

Here is a proof of concept for what would need done to translate parameters to always be lower case:

$QueryParameters = $QueryParameters | %{
  $ht = @{}
  $_.getenumerator() | %{
    $ht.add($_.Name.ToLower(),$_.Value)
  }
  $ht
}

I'd expect the performance hit to be quite minimal if implemented. Alternatively, it could be nice to check if the hashtable array contains any name or value keys that aren't fully lower case and error if so. Thoughts on what direction you'd like to go?

PlagueHO commented 2 years ago

Hi @Szeraax - ah yes, I see what you mean. It doesn't specifically call this out in the docs (https://docs.microsoft.com/en-us/rest/api/cosmos-db/query-documents), but makes sense. The fix makes sense, but just would need slight style adjustments. What I'd also suggest is moving the whole code block to a helper function that we can put unit tests on (just makes testing easier). Happy to do this or take a PR if you want?