[MAGNOLIA-8936] Link to deleted Page leads to Template-Exception Created: 11/May/23  Updated: 18/Jun/23  Resolved: 29/May/23

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 6.2.33
Fix Version/s: 6.3.0, 6.2.35

Type: Bug Priority: Normal
Reporter: Carlos Cantalapiedra Assignee: Jaromir Sarf
Resolution: Fixed Votes: 0
Labels: VN-Testing
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: 3h Time Spent: 3h
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Attachments: PNG File english-ref.png     PNG File freemarker-error.png     PNG File german-ref.png    
Issue Links:
Problem/Incident
Relates
relates to MAGNOLIA-8931 rendering of RichTextField data fails... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
MAGNOLIA-8937 Implementation Sub-task Completed Jaromir Sarf  
MAGNOLIA-8938 Code review Sub-task Completed Adam Siska  
MAGNOLIA-8939 Pre-integration QA + PM (for ticket a... Sub-task Completed Adam Siska  
MAGNOLIA-8940 Final QA Sub-task Completed Quach Hao Thien  
Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[X]* Steps to reproduce, expected, and actual results filled
[X]* Affected version filled
Release notes required:
Yes
Date of First Response:
Sprint: Nucleus 37
Story Points: 2
Team: Nucleus
Work Started:
Approved:
Yes

 Description   

Steps to reproduce

  1. Site-App
    1. select "travel"-Node
    2. click "Duplicate Item"
    3. update "/travel0/mappings/website@handlePrefix" to "/travel/about"
  2. Pages-App
    1. select "/travel/about/careers"
      1. click "Add page"
      2. Pagename "test1", Template "Basic Template"
    2. select "/travel/about/careers"
      1. click "Add page"
      2. Pagename "test2", Template "Basic Template"
    3. Edit Page "/travel/about/careers/test1"
      1. Add Component "Text and Image" in Main
      2. Edit the created Component
      3. Insert in the RichTextField the Text Link
      4. Click on Button "Link to Magnolia Page"
      5. Select "/travel/about/careers/test2"
      6. Close the page
    4. select "/travel/about/careers/test2"
    5. click "Delete Page" => "Publish Deletion"
  3. Task-App
    1. Assign Task
    2. Accept an publish Deletion
  4. reopen Pages-App
    1. check if test2 is deleted
    2. reopen check1
    3. change language to "German"
    4. => EXCEPTION

Expected results

Tho the page doesn't exist, no error is thrown or, at least, the message "The referenced content does not exist" is displayed.

Actual results

Exception is thrown

Workaround

N/A

Development notes

Similar behavior for Link component. When you create a link component to a page and then, delete the page, the message "The referenced content does not exist" is shown for English but if you switch to German, the exception is thrown. It is weird that if at this point, you switch back to English, the Framework exception is thrown also for English. Probably, because the referenced page is still within the Link field:

If you move to German language, Magnolia copies the dead reference to the German field:



 Comments   
Comment by Jaromir Sarf [ 22/May/23 ]

Discovery:
Issue is caused by NPE in https://git.magnolia-cms.com/projects/PLATFORM/repos/main/browse/magnolia-templating/src/main/java/info/magnolia/templating/functions/TemplatingFunctions.java#893 when the node was not found. The solution could be to return null from this function when the node was not found, e.g. by catching ItemNotFoundException.

public Node contentByReference(Node content, String idPropertyName, String referencedWorkspace) throws RepositoryException {
    if (content.hasProperty(idPropertyName)) {
        try{
            final String identifier = PropertyUtil.getString(content, idPropertyName);
            final Node node = NodeUtil.getNodeByIdentifier(referencedWorkspace, identifier);
            return encode(wrapForI18n(node));
        } catch (ItemNotFoundException e){
            return null;
        }
    }
    return null;
} 
Generated at Mon Feb 12 04:37:08 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.