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

Allow for Leading "/" In Partition Keys When Creating Collections #153

Closed
ledbutter opened this issue Aug 17, 2018 · 1 comment · Fixed by #154
Closed

Allow for Leading "/" In Partition Keys When Creating Collections #153

ledbutter opened this issue Aug 17, 2018 · 1 comment · Fixed by #154
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@ledbutter
Copy link
Contributor

Before submitting your issue for the CosmosDB project, please take a moment to provide the following details:

  • [ 5.1.17134.228 ] Version of PowerShell you're using
  • [ Console ] PowerShell host you're using (eg. Console Host, ISE, Visual Studio)
  • [Windows 10 ] Operating system you're running
  • [ 2.1.5.548 ] Version of CosmosDB PowerShell Module you're using (use Get-Module -Name CosmosDB)

I only came across this by mimicking the behavior in the Azure portal, where it suggests a partition key of "/address/zipCode", so I tried entering in a partition key of "/Document/MyId" via:
New-CosmosDBCollection -Context @ctx -PartitionKey "/Document/MyId" -Id Test

And I got the following response:

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.

Digging deeper, I get:

"The partition key component definition path '\/\/Document\/MyId' could not be accepted, failed near position '1'. Partition key paths must contain only valid characters and not contain a trailing slash or wildcard character.

I only figured out what was actually going on by digging into the source here.

This seems like a simple change to only prepend "/" if the $PartitionKey does not already start with one.

I'd be happy to submit the fix myself if this is something useful to anyone besides me.

@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Aug 17, 2018
@PlagueHO
Copy link
Owner

Hi @ledbutter - great catch and thank you for submitting this. Definitely happy to accept a PR if you're happy to submit it! 😁 Otherwise I'll be doing some more work on this module later this week.

PlagueHO added a commit that referenced this issue Aug 24, 2018
Trim leading slashes off of partition key value in lib\collections.ps1. Fixes: #153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
2 participants