From 550d69ed209d0c22e292f251778b5d5a2183371d Mon Sep 17 00:00:00 2001 From: Sumalatha G Date: Mon, 2 Mar 2026 12:30:51 +0530 Subject: [PATCH 1/2] Fix Jinja2 template error when IPv6 is disabled on subinterface Fix for issue sonic-net/sonic-buildimage#23323 The show_interface.j2 template throws a jinja2.exceptions.UndefinedError when IPv6 is disabled on a subinterface because it doesn't check if the 'addresses' field exists before accessing it. When IPv6 is disabled on a subinterface, the openconfig-if-ip:ipv6 object exists but does not contain an 'addresses' field. The template was checking if the ipv6 object exists but then immediately trying to access the addresses field without verifying its existence. This change adds a conditional check to ensure the 'addresses' field exists in the openconfig-if-ip:ipv6 object before attempting to access it. Test scenarios: - IPv6 disabled (no addresses field) - works without errors - IPv6 enabled (with addresses field) - works as before Signed-off-by: Sumalatha G --- CLI/renderer/templates/show_interface.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLI/renderer/templates/show_interface.j2 b/CLI/renderer/templates/show_interface.j2 index 8e50d6fc74..c45e13e9bd 100644 --- a/CLI/renderer/templates/show_interface.j2 +++ b/CLI/renderer/templates/show_interface.j2 @@ -76,7 +76,7 @@ {% if vars.update({'ipv4_src_pfx':""}) %}{% endif %} {% if vars.update({'mode4':"not-set"}) %}{% endif %} {% endif %} - {% if subif["openconfig-if-ip:ipv6"] %} + {% if subif["openconfig-if-ip:ipv6"] and "addresses" in subif["openconfig-if-ip:ipv6"] %} {% set ip_list = subif["openconfig-if-ip:ipv6"]["addresses"]["address"] %} {% set ipv6_all = [] %} {% for ip in ip_list %} From 9e1b291b2041964dfb78ac3ab12e14e392ce7212 Mon Sep 17 00:00:00 2001 From: Sumalatha G Date: Tue, 3 Mar 2026 10:57:36 +0530 Subject: [PATCH 2/2] Fix same bug in show_interface_id.j2 template As pointed out by GitHub Copilot review, the show_interface_id.j2 template has the identical bug on line 76. It checks if the ipv6 object exists but doesn't verify the 'addresses' field exists before accessing it. This commit applies the same fix to show_interface_id.j2 that was applied to show_interface.j2 - adding a check to ensure the 'addresses' field exists before attempting to access it. Signed-off-by: Sumalatha G --- CLI/renderer/templates/show_interface_id.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLI/renderer/templates/show_interface_id.j2 b/CLI/renderer/templates/show_interface_id.j2 index b4b4b32eed..5d29fc87f7 100644 --- a/CLI/renderer/templates/show_interface_id.j2 +++ b/CLI/renderer/templates/show_interface_id.j2 @@ -73,7 +73,7 @@ {% else %} {% if vars.update({'mode4':"not-set"}) %}{% endif %} {% endif %} - {% if subif["openconfig-if-ip:ipv6"] %} + {% if subif["openconfig-if-ip:ipv6"] and "addresses" in subif["openconfig-if-ip:ipv6"] %} {% set ip_list = subif["openconfig-if-ip:ipv6"]["addresses"]["address"] %} {% set ipv6_all = [] %} {% for ip in ip_list %}