diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs index 7b34e18405..f787b49dac 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs @@ -186,9 +186,7 @@ public override async Task CreateContainerIfNotExistsAsync( if (response.StatusCode != HttpStatusCode.NotFound) { ContainerResponse retrivedContainerResponse = await this.ClientContext.ResponseFactory.CreateContainerResponseAsync(container, Task.FromResult(response)); - if (!PartitionKeyDefinition.AreEquivalent( - retrivedContainerResponse.Resource.PartitionKey, - containerProperties.PartitionKey)) + if (!retrivedContainerResponse.Resource.PartitionKeyPath.Equals(containerProperties.PartitionKeyPath)) { throw new ArgumentException( string.Format( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs index a6269169a8..3098694fff 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs @@ -184,6 +184,41 @@ public async Task CreateContainerIfNotExistsAsyncTest() containerResponse = await containerResponse.Container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); + + + //Creating existing container with partition key having value for SystemKey + //https://github.com/Azure/azure-cosmos-dotnet-v3/issues/623 + string v2ContainerName = "V2Container"; + PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); + partitionKeyDefinition.Paths.Add("/test"); + partitionKeyDefinition.IsSystemKey = false; + ContainerProperties containerPropertiesWithSystemKey = new ContainerProperties() + { + Id = v2ContainerName, + PartitionKey = partitionKeyDefinition, + }; + await this.cosmosDatabase.CreateContainerAsync(containerPropertiesWithSystemKey); + + ContainerProperties containerProperties = new ContainerProperties(v2ContainerName, "/test"); + containerResponse = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerProperties); + Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); + Assert.AreEqual(v2ContainerName, containerResponse.Resource.Id); + Assert.AreEqual("/test", containerResponse.Resource.PartitionKey.Paths.First()); + + containerResponse = await containerResponse.Container.DeleteContainerAsync(); + Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); + + containerPropertiesWithSystemKey.PartitionKey.IsSystemKey = true; + await this.cosmosDatabase.CreateContainerAsync(containerPropertiesWithSystemKey); + + containerProperties = new ContainerProperties(v2ContainerName, "/test"); + containerResponse = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerProperties); + Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); + Assert.AreEqual(v2ContainerName, containerResponse.Resource.Id); + Assert.AreEqual("/test", containerResponse.Resource.PartitionKey.Paths.First()); + + containerResponse = await containerResponse.Container.DeleteContainerAsync(); + Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); } [TestMethod] diff --git a/changelog.md b/changelog.md index 2e765f146d..685df06a6f 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#612](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/612) Bug fix for ReadFeed with partition-key - [#614](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/614) Fixed SpatialPath serialization and compatibility with older index versions - [#626](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/626) FeedResponse status code now return OK for success instead of the invalid status code 0 or Accepted +- [#629](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/629) Fixed CreateContainerIfNotExistsAsync validation to limited to partitionKeyPath only ## [3.1.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.1.0) - 2019-07-26