Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Runar Løseth 11 posts 92 karma points
    Aug 26, 2021 @ 08:13
    Runar Løseth
    0

    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):

    enter image description here

    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:

    enter image description here

    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.

    enter image description here

    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?

Please Sign in or register to post replies

Write your reply to:

Draft