Skip to content

Versioning_Engine: Fix Issue with all dictionary entries throwing and catching exceptions #3518

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Versioning_Engine/Modify/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**** Public Methods ****/
/***************************************************/

public static BsonDocument Upgrade(this BsonDocument document, Converter converter)

Check warning on line 42 in Versioning_Engine/Modify/Upgrade.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Versioning_Engine/Modify/Upgrade.cs#L42

Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType

Check warning on line 42 in Versioning_Engine/Modify/Upgrade.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Versioning_Engine/Modify/Upgrade.cs#L42

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
{
if (document == null)
return null;
Expand All @@ -60,7 +60,7 @@
}
else if (newDoc.Contains("k") && newDoc.Contains("v"))
{
result = UpgradeObject(newDoc, converter);
result = UpgradeObjectProperties(newDoc, converter); //Calling UpgradeObjectProperties directly here, as that is the only part of UpgradeObject method that is relevant. All other parts require _t to be set
}

return result;
Expand Down Expand Up @@ -204,13 +204,12 @@

private static BsonDocument UpgradeObject(BsonDocument document, Converter converter)
{

if (!document.Contains("_t"))
return UpgradeObjectProperties(document, converter); //Only method relevant to be called for the case of no type available

//Get the old type
string oldType = "";
try
{
oldType = CleanTypeString(document["_t"].AsString);
}
catch { }
string oldType = CleanTypeString(document["_t"].AsString);

// Check if the object type is classified as deleted or without update
CheckForNoUpgrade(converter, oldType, "object type");
Expand Down Expand Up @@ -309,18 +308,18 @@

private static BsonDocument UpgradeObjectExplicit(BsonDocument document, Converter converter, string oldType)
{
try
{
Dictionary<string, object> b = converter.ToNewObject[oldType](document.ToDictionary());
if (b == null)
return null;

BsonDocument newDoc = new BsonDocument(b);

// Copy over BHoM properties if the old object was a BHoMObject (assumption around BHoM_Guid made here)
if (document.Contains("BHoM_Guid"))
{
string[] properties = new string[] { "BHoM_Guid", "CustomData", "Name", "Tags", "Fragments" };

Check warning on line 322 in Versioning_Engine/Modify/Upgrade.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Versioning_Engine/Modify/Upgrade.cs#L322

The use of CustomData within the code is discouraged except in circumstances where volatile data is being used. - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsUsingCustomData
foreach (string p in properties)
{
if (!newDoc.Contains(p) && document.Contains(p))
Expand Down