Numeric fields with unset value causes null-exceptions
I've been running into some strange behaviour from numeric fields after upgrading to Umbraco 8.15 on two projects. Numeric fields do not seem to be included in models if the value is unset when a page is loaded for the first time.
Example 1: In the auto-generated model for a document type including a numeric field set to optional, min value 0, step size 1, if the value of this field is unset when rendering a page the following line in the model causes a null-exception on the Model property itself (not the value returned):
In another project the error is being thrown in the actual view instead of the generated model. This time the numeric field is optional, no min value, no step size. The following occurs in the view if the value is unset:
At first I thought the numeric field was returning a null-value and that was causing the error, but it's actually the field "testNumeric" itself that is nowhere to be found. Wrapping the code in a .HasValue() fixes this.
This fix works fine for circumventing the issue on a view, but it goes without saying that this is not an option for an automatically generated model.
So is this an actual intentional change to the numeric field behaviour made somewhere in the latest versions of Umbraco or is it a bug that can be fixed somehow?
One extra bit of information on this, this seems to only be happening when intially loading a up a page. Refreshing the page causes no error. Navigating to another page using the same template however does cause the error to reappear.
Numeric fields with unset value causes null-exceptions
I've been running into some strange behaviour from numeric fields after upgrading to Umbraco 8.15 on two projects. Numeric fields do not seem to be included in models if the value is unset when a page is loaded for the first time.
Example 1: In the auto-generated model for a document type including a numeric field set to optional, min value 0, step size 1, if the value of this field is unset when rendering a page the following line in the model causes a null-exception on the Model property itself (not the value returned):
In another project the error is being thrown in the actual view instead of the generated model. This time the numeric field is optional, no min value, no step size. The following occurs in the view if the value is unset:
At first I thought the numeric field was returning a null-value and that was causing the error, but it's actually the field "testNumeric" itself that is nowhere to be found. Wrapping the code in a .HasValue() fixes this.
This fix works fine for circumventing the issue on a view, but it goes without saying that this is not an option for an automatically generated model.
So is this an actual intentional change to the numeric field behaviour made somewhere in the latest versions of Umbraco or is it a bug that can be fixed somehow?
One extra bit of information on this, this seems to only be happening when intially loading a up a page. Refreshing the page causes no error. Navigating to another page using the same template however does cause the error to reappear.
I also found this, Rasmus Trumf reported the same error back in April but didn't get any response: https://our.umbraco.com/forum/using-umbraco-and-getting-started/105682-not-set-value-in-numeric-datatype-causes-exception-in-models-builder-generated-file
Does anyone have any idea why this is happening and if there's a fix for the generated models?
is working on a reply...