Skip to content

Commit

Permalink
[Internal] ContainerProperties: Fixes version reset when setting Part…
Browse files Browse the repository at this point in the history
…itionKeyPath (#3637)

* Remember previous value

* test
  • Loading branch information
ealsur committed Jan 9, 2023
1 parent 3c875c7 commit 416b154
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,17 @@ public string PartitionKeyPath
throw new ArgumentNullException(nameof(this.PartitionKeyPath));
}

PartitionKeyDefinitionVersion? currentDefinitionVersion = this.PartitionKeyDefinitionVersion;

this.PartitionKey = new PartitionKeyDefinition
{
Paths = new Collection<string>() { value }
};

if (currentDefinitionVersion.HasValue)
{
this.PartitionKeyDefinitionVersion = currentDefinitionVersion.Value;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ public void ValidateIncludedPathSerialization()
}
}

[TestMethod]
public void SettingPKShouldNotResetVersion()
{
ContainerProperties containerProperties = new();
containerProperties.Id = "test";
containerProperties.PartitionKeyDefinitionVersion = Cosmos.PartitionKeyDefinitionVersion.V2;
containerProperties.PartitionKeyPath = "/id";

Assert.AreEqual(Cosmos.PartitionKeyDefinitionVersion.V2, containerProperties.PartitionKeyDefinitionVersion);
}

private static string SerializeDocumentCollection(DocumentCollection collection)
{
using (MemoryStream ms = new MemoryStream())
Expand Down

0 comments on commit 416b154

Please sign in to comment.