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

[OData] Cannot update Reference field with empty array as value #438

Closed
herflis opened this Issue Aug 6, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@herflis
Copy link
Contributor

herflis commented Aug 6, 2018

I have to update a reference field trough OData, and if I send the value as an array with at least one item it works as it should, but when I have to make the Reference field empty and send the request with an empty array as a value, I get NullReferenceException.

Steps to reproduce

$.ajax({
     url: "/OData.svc/Root/IMS/BuiltIn/Demo/ProjectManagers('rupertbrown')",
     dataType: "json",
     type: 'PATCH',
     data: "models=[" + JSON.stringify({'FollowedWorkspaces': [4758] }) + "]",
     success: function () {
		console.log('Field is successfully modified');
     }
});

then

$.ajax({
     url: "/OData.svc/Root/IMS/BuiltIn/Demo/ProjectManagers('rupertbrown')",
     dataType: "json",
     type: 'PATCH',
     data: "models=[" + JSON.stringify({'FollowedWorkspaces': [] }) + "]",
     success: function () {
		console.log('Field is successfully modified');
     }
});

image

I've tried to set it to an empty array, string and even to null, but got the same error.

@herflis herflis added the bug label Aug 6, 2018

@tusmester

This comment has been minimized.

Copy link
Member

tusmester commented Aug 6, 2018

Pls post the error call stack (trace property) from the console (shown on the screenshot above).

@herflis

This comment has been minimized.

Copy link
Contributor Author

herflis commented Aug 6, 2018

I know, I know, it's soooooo difficult to use the requests above on a test site and check it :P

ODataException: Object reference not set to an instance of an object.\r\n\r\n---- Inner Exception:\r\nNullReferenceException: Object reference not set to an instance of an object.\r\n at SenseNet.ContentRepository.Storage.Node.AddReferences[T](NodeList1 nodeList, IEnumerable1 refNodes, Boolean distinct) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\Storage\\Node.cs:line 1339\r\n at SenseNet.ContentRepository.Storage.Node.AddReferences[T](String propertyName, IEnumerable1 refNodes, Boolean distinct) in C:\Builds\8\SenseNet\DemoBuildForLATESTRELEASE\Sources\Source\SenseNet\Storage\Node.cs:line 1245\r\n at SenseNet.ContentRepository.Storage.Node.AddReferences[T](String propertyName, IEnumerable1 refNodes) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\Storage\\Node.cs:line 1233\r\n at SenseNet.ContentRepository.Storage.Node.SetReferences[T](String propertyName, IEnumerable1 nodes) in C:\Builds\8\SenseNet\DemoBuildForLATESTRELEASE\Sources\Source\SenseNet\Storage\Node.cs:line 1192\r\n at SenseNet.ContentRepository.User.set_FollowedWorkspaces(IEnumerable1 value) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\User.cs:line 323\r\n at SenseNet.ContentRepository.User.SetProperty(String name, Object value) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\User.cs:line 1105\r\n at SenseNet.ContentRepository.Field.WriteProperty(String propertyName, Object value) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Field.cs:line 231\r\n at SenseNet.ContentRepository.Field.WriteProperties(Object value) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Field.cs:line 216\r\n at SenseNet.ContentRepository.Field.Save(Boolean validOnly) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Field.cs:line 313\r\n at SenseNet.ContentRepository.Content.SaveFields(Boolean validOnly) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Content.cs:line 1007\r\n at SenseNet.ContentRepository.Content.Save(Boolean validOnly, SavingMode mode) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Content.cs:line 1081\r\n at SenseNet.ContentRepository.Content.Save(Boolean validOnly) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Content.cs:line 1047\r\n at SenseNet.ContentRepository.Content.Save() in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\ContentRepository\\Content.cs:line 1039\r\n at SenseNet.Portal.OData.ODataHandler.UpdateContent(Content content, JObject model, ODataRequest odataRequest) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\Portal\\OData\\ODataHandler.cs:line 527\r\n at SenseNet.Portal.OData.ODataHandler.ProcessRequest(HttpContext context, String httpMethod, Stream inputStream) in C:\\Builds\\8\\SenseNet\\DemoBuildForLATESTRELEASE\\Sources\\Source\\SenseNet\\Portal\\OData\\ODataHandler.cs:line 187\r\n=====================\r\n

@tusmester

This comment has been minimized.

Copy link
Member

tusmester commented Aug 6, 2018

Possible cause: a missing null check here:

foreach (var node in refNodes)

@tusmester tusmester self-assigned this Aug 7, 2018

@tusmester tusmester added this to the Sprint 165 milestone Aug 10, 2018

@tusmester

This comment has been minimized.

Copy link
Member

tusmester commented Aug 13, 2018

@herflis pls review.

@herflis herflis assigned herflis and unassigned tusmester Aug 15, 2018

@herflis herflis closed this Aug 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment