Skip to content
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

Numeric properties cannot be nullable #10369

Closed
terabyte-developers opened this issue Jun 1, 2021 · 3 comments
Closed

Numeric properties cannot be nullable #10369

terabyte-developers opened this issue Jun 1, 2021 · 3 comments
Labels

Comments

@terabyte-developers
Copy link

terabyte-developers commented Jun 1, 2021

Which Umbraco version are you using?

8.10.1

Bug summary

the following code returns zero if the property is not set:
ipc.Value<decimal?>(alias)

Specifics

No response

Steps to reproduce

Create a property with 'numeric' datatype.
Set it's value to nothing (blank).
Use the API to access the property like so:
var x = ipc.Value<decimal?>(alias)

Expected result / actual result

If the property in the CMS is blank then x should be null. But it is 0
If the property in the CMS is 0 then x should be 0.

@Myster
Copy link
Contributor

Myster commented Jun 1, 2021

Workaround:

if (ipc.GetProperty(alias).HasValue()) // https://github.com/umbraco/Umbraco-CMS/issues/10369
{
	result.Value = ipc.Value<decimal?>(alias); 
}

@nul800sebastiaan
Copy link
Member

Just for clarification: I'm not sure what ipc is? Where does it come from please?

In any case, this is the current behavior and unfortunately we can not change it now, it will be a breaking change because everybody who is currently expecting to see a 0 as a result and is not counting on getting a null as a result is going to have broken sites if we change this. It's very unfortunate but I'm afraid we'll have to live with inconsistencies like this for a bit longer. I think for your case this might be a really nice contribution to: https://our.umbraco.com/packages/developer-tools/supervalueconverters/

On our todo list for a future version (beyond v9), is to make this package obsolete, but if it helps you feel a little bit better about the bad choices we made in the past, I would encourage you to use and contribute to that! 👍

@Myster
Copy link
Contributor

Myster commented Jun 2, 2021

Ahh breaking change yea, that makes sense :-(
Sorry, ipc is an instance of an IPublishedContent, ultimately it would come from something like Current.UmbracoContext.PublishedRequest.PublishedContent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants