U4-6047 - Related Links - Leaving the Link field empty causes YSOD

Created by Matthew 22 Dec 2014, 22:48:32 Updated by Sigurd Aabøe-Sagen 21 Feb 2017, 19:01:11

I have a standard related links data type in a document. On the content creation side, I create a new link but only input a caption before hitting Add, leaving the link field empty on the internal link setting. This results in a YSOD on the front end page that is using the example typed razor syntax found here: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/Related-Links

I added a line that checks to see if the related link is a valid JArray. This prevent the YSOD, but doesn't render anything from the related links, even if there are other, valid inputs.

This is an issue for me because backoffice users may expect to add captions without internal links if they haven't made the desired link page yet.

Images attached, including the YSOD.

2 Attachments

Comments

Jeavon Leopold 19 Jan 2015, 15:10:55

I don't think this is a bug. It's being caused by your recursive lookup hitting a node up the tree without the property on it. I think a recursive HasValue check should stop it occurring. e.g. @{
if (Model.Content.HasValue("subNavigation", true)) {

    @foreach (var item in Model.Content.GetPropertyValue("subNavigation", true)) { var linkUrl = (item.Value("isInternal")) ? Umbraco.NiceUrl(item.Value("internal")) : item.Value("link"); var linkTarget = item.Value("newWindow") ? "_blank" : null;
  • @(item.Value("caption"))
  • }
} }


Matthew 20 Jan 2015, 18:40:37

I am using the HasValue mehod. Please see: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/Related-Links

I have copied this example code almost verbatim. Aside from that, HasValue (as you're using above) is checking to see if the Related Links control is populated; not whether a given internal link is empty, which causes the problems I mention in my original post.


Jeavon Leopold 20 Jan 2015, 18:51:13

The difference is that you are looking recursively up to the tree for a value, the HasValue must also check recursively. e.g. HasValue("subNavigation", true) The only way I can recreate your issue is by not having that recursive check, you can have empty links and it doesn't throw a YSOD. You can see in your YSOD that the error is on line 144 which is converting the value to JArray, it has nothing to do with the empty links.


Matthew 20 Jan 2015, 19:54:57

I'll give that a shot later, but I was almost positive that I still got the YSOD without the recursive call in both the HasValue and GetPropertValue methods.


Sigurd Aabøe-Sagen 21 Feb 2017, 19:01:11

Just ran into this issue on version 7.5.3. And still get the YSOD.. In my case i have several links in the list but by adding another without a link it fails.

By following this steps you will get an error:

  1. Add some text as caption
  2. Do not Click choose (for internal page)
  3. Click ADD.

There should be a warning that its not possible to save a link in the list that is either empty (if external) or empty if internal.


Priority: Normal

Type: Bug

State: Submitted

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.2.1

Due in version:

Sprint:

Story Points:

Cycle: