U4-2730 - 500 - PostSave

Created by Warren Buckley (Personal) 27 Aug 2013, 11:53:07 Updated by Shannon Deminick 18 Sep 2013, 23:58:02

Subtask of: U4-2891

Hello Shan, I have a 500 error with PostSave (http://localhost:59340/umbraco/UmbracoApi/Content/PostSave)

{ "Message":"Anerrorhasoccurred.", "ExceptionMessage":"Objectreferencenotsettoaninstanceofanobject.", "ExceptionType":"System.NullReferenceException", "StackTrace":"atUmbraco.Web.Editors.ContentPostValidateAttribute.OnActionExecuting(HttpActionContextactionContext)\r\natSystem.Web.Http.Filters.ActionFilterAttribute.System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync(HttpActionContextactionContext,CancellationTokencancellationToken,Func`1continuation)" }

This is the JSON sent { "id":0, "properties":[ { "id":0, "alias":"siteName", "value":"Hello World" }, { "id":0, "alias":"siteDescription", "value":"Hello there" }, { "id":0, "alias":"bodyText", "value":"

Something here

" }, {
"id":0, "alias":"userPicker", "value":0 } ], "name":"Home", "contentTypeAlias":"umbHomepage", "parentId":-1, "action":"publishNew", "releaseDate":null, "expireDate":null }

I am trying to build a simple PropertyEditor that stores an integer of the selected Umbraco backoffice user from a dropdown.

My package manifest JSON is like so: { propertyEditors: [
{ id: "8a02c8fe-4d5d-4e6e-9525-e9a529928048", name: "(CWS) User Picker", editor: { view: "/App_Plugins/UserPicker/user-picker.html", valueType: 'int' } } ] , javascript: [ '/App_Plugins/UserPicker/userpicker.controller.js' ] }

So I think the issue is with me trying to save the value as an int in Umbraco, as this was working fine when saving the value as a string. However when the dropdown was reloaded the selected item was not selected as the id was stored a string and the JSON for users is an int. Hence the need to store this as an int in Umbraco.

My view for user picker

<div class="row">
    <select name="{{ model.alias }}" ng-model=" model.value" ng-options="user.id as user.name for user in users">
        <option value="">Select User</option>
    </select>
</div>

<hr/>

<h6>Debug JSON</h6>
{{ model | json }}

<h6>Users JSON</h6>
{{ users | json }}

<h6>Selected User</h6>
{{ model.value }}
{code}

And finally my controller for this angular.module("umbraco").controller("CWS.UserPickerController", function ($scope, $log, assetsService, userResource, notificationsService) {

//Start log message
$log.log("Start User Picker Controller");

//Try and getAll() users
userResource.getAll().then(function (userArray) {
    
    //Log message - we got the users
    $log.log("Get All Users Returned");

    //Get the array of users back from getAll()
    var users = userArray;
    
    //Log the array
    $log.log(users);

    //Set the users variable into our scope
    $scope.users = users;
});

//now we need to check if the value is null/undefined, if it is we need to set it to "" so that any value that is set
// to "" gets selected by default
if ($scope.model.value === null || $scope.model.value === undefined) {
    $scope.model.value = "";
}

//Ending log message
$log.log("End User Picker Controller");

});

Cheers, Warren :)

1 Attachments

Comments

Shannon Deminick 28 Aug 2013, 03:02:01

SO it was working with string ?

There's currently an issue with the content service caching when data types change. Have you tried restarting your app pool after the the data type has been saved again so it knows to save the data as int ?


Warren Buckley (Personal) 28 Aug 2013, 09:44:31

Hello Shannon, I done a clean install from the latest nightly and tried again. I am now getting a new YSOD from PostSave

I am sending 0 as the value from the user picker property aka the Admin user in Umbraco.

{ "id":1051, "properties":[ { "id":10, "alias":"siteName", "value":"Simple website" }, { "id":11, "alias":"siteDescription", "value":"Off to a great start" }, { "id":12, "alias":"bodyText", "value":"\r\n

The Simple Starter Kit gives you a bare-bones website that\r\nintroduces you to a set of well-defined conventions for building an\r\nUmbraco website.

\r\n\r\n

The Simple website is very basic in form and provided without\r\nany design or functionality - unless you add a Skin, of course. By\r\ninstalling the Simple Starter Kit, you'll begin with a minimal site\r\nbuilt on best practices. You'll also enjoy the benefits of speaking\r\nthe same "language" as the rest of the Umbraco community by using\r\ncommon properties and naming conventions.

\r\n\r\n

Now that you know what the Simple site is, it is time to get\r\nstarted using Umbraco.

\r\n" }, { "id":19, "alias":"user", "value":0 }], "name":"Simple website", "contentTypeAlias":"umbHomepage", "parentId":-1, "action":"publish", "releaseDate":null, "expireDate":null }

{ "Message":"An error has occurred.", "ExceptionMessage":"The value Umbraco.Core.Models.Editors.ContentPropertyData cannot be converted to the type Integer", "ExceptionType":"System.InvalidOperationException","StackTrace":" at Umbraco.Core.PropertyEditors.ValueEditor.FormatDataForPersistence(ContentPropertyData editorValue, Object currentValue) in f:\TeamCity\buildAgent\work\e1a0ddf7a1349eaf\src\Umbraco.Core\PropertyEditors\ValueEditor.cs:line 175\r\n at Umbraco.Web.Editors.ContentControllerBase.MapPropertyValues[TPersisted](ContentItemSave1 contentItem)\r\n at Umbraco.Web.Editors.ContentController.PostSave(ContentItemSave1 contentItem)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)" }


Warren Buckley (Personal) 28 Aug 2013, 10:00:02

Looking at that class that this YSOD is coming from I cannot see what the issue is as the code seems all OK. Think I will try and download the source and step through that class to see what the issue is.

https://github.com/umbraco/Umbraco-CMS/blob/7.0.0/src/Umbraco.Core/PropertyEditors/ValueEditor.cs


Warren Buckley (Personal) 28 Aug 2013, 10:27:29

Here is a screenshot from TryConvertValueToCrlType.

As the screenshot shows. It cannot cast a Int64 to a Nullable Int32 hence the YSOD I am getting.


Shannon Deminick 29 Aug 2013, 07:21:37

strange, now just trying to figure out why it is posting as int 64


Shannon Deminick 29 Aug 2013, 07:24:15

I think Json.Net must format a json numeric as int 64. My numeric property editor is posting the value as a string which is then converted to an int, i guess to date I haven't tried just posting a json numerical value! I'll fix up.


Shannon Deminick 29 Aug 2013, 07:26:53

I've made the change in this revision: 52700c0c18c8771e1200e3307d2ec5462c14476b

So if you can test with that change, that would be great. If it doesn't work, please re-open and let me know what happened.


Warren Buckley (Personal) 29 Aug 2013, 08:45:27

OK would it be built into a nightly or do I need to download the source and build out a release zip from there?


Shannon Deminick 29 Aug 2013, 08:49:03

If you are actively working with belle I would strongly recommend that you just work based on the repo since it changes heavily every day. Otherwise if the nighties are working you'll have to wait till it's out.


Warren Buckley (Personal) 29 Aug 2013, 08:51:10

OK I will work with the repo instead then


Warren Buckley (Personal) 29 Aug 2013, 11:12:19

Yes its saving the integer just fine now. Now I have an issue with the dropdown not selecting the correct item from the value saved in $scope.model.value


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.0.0

Due in version: 7.0.0

Sprint:

Story Points:

Cycle: