Skip to content

Conversation

@amaanhaque
Copy link
Contributor

Pull Request Template

Description

The move operation removes the value at a specified location and adds it to the target location.
It takes in 2 parameters "path" (destination path) and "from" (source path).
Functionally it is identical to an add operation at the destination followed by a remove at the source path.
This operation is discussed in the JSONPATCH RFC6902.

Type of change

Please delete options that are not relevant.

  • [] New feature (non-breaking change which adds functionality)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

@ealsur
Copy link
Member

ealsur commented Jun 10, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 3262 in repo Azure/azure-cosmos-dotnet-v3

@ealsur
Copy link
Member

ealsur commented Jun 13, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@ealsur ealsur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emulator tests are failing with:
Microsoft.Azure.Cosmos.CosmosException: Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d48a11a6-af63-47ff-b6ea-1146e212e8a1; Reason: (Message: {"Errors":["Invalid value of the patch operation 'op' property in patch request: 'move'"]}

Does this require a new Emulator release?

@amaanhaque
Copy link
Contributor Author

Emulator tests are failing with: Microsoft.Azure.Cosmos.CosmosException: Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d48a11a6-af63-47ff-b6ea-1146e212e8a1; Reason: (Message: {"Errors":["Invalid value of the patch operation 'op' property in patch request: 'move'"]}

Does this require a new Emulator release?

It doesn't.

@amaanhaque amaanhaque requested a review from ealsur June 15, 2022 05:33
/// Source location reference (used in case of move)
/// </summary>
[JsonProperty(PropertyName = PatchConstants.PropertyNames.From)]
public abstract string From { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Adding any new abstract member on a public non-sealed class is considered breaking. Because customers could have inherited from that class and now would hit a compiler error. Make this property virtual please with a default (I assume returning null when you follow what you did in Java)


this.From = string.IsNullOrWhiteSpace(value.ToString())
? throw new ArgumentNullException(nameof(value))
: value.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing prevents value form being null in the first place. And that would result in a NullReferenceException here. String.IsNullOrWhiteSpace(value) instead of String.IsNullOrWhiteSpace(value.ToString()) fixes that

[EnumMember(Value = PatchConstants.OperationTypeNames.Increment)]
Increment,

/// <summary>
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking adding new enum values is also breaking - I think this is acceptable here because it clearly is a contract class - but that is the reason why usually it is a bad idea in frameworks to expose enums in Json contract classes - and usage of Strings is safer.

Please add a comment on this enum - class level to clearly call out that customers should expect to values to be added - and any switch / case assuming new enums would only be added for new major (breaking) versions is discouraged.

{
writer.WritePropertyName(PatchConstants.PropertyNames.From);
writer.WriteValue(operation.From);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be else if here - if it is move value would never be needed

/// <param name="from">The source location of the object/value.</param>
/// <returns>PatchOperation instance for specified input.</returns>
public static PatchOperation Move(
string path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java you have switched the order PatchOperation Move(string from, string path) - I personally think that is much more intuitive. And would be my preference for .Net as well.

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good - few comments that need to be addressed

@ealsur
Copy link
Member

ealsur commented Aug 25, 2022

Duplicate of #3389

@ealsur ealsur marked this as a duplicate of #3389 Aug 25, 2022
@ealsur ealsur closed this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants