Skip to content

Fix Jinja2 template error when IPv6 is disabled on subinterface#156

Open
Sumalatha-G-ML wants to merge 2 commits intosonic-net:masterfrom
Sumalatha-G-ML:fix-issue-23323-ipv6-subinterface
Open

Fix Jinja2 template error when IPv6 is disabled on subinterface#156
Sumalatha-G-ML wants to merge 2 commits intosonic-net:masterfrom
Sumalatha-G-ML:fix-issue-23323-ipv6-subinterface

Conversation

@Sumalatha-G-ML
Copy link

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

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 <sumalatha.g@xoriant.com>
@mssonicbld
Copy link

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Sumalatha-G-ML
Copy link
Author

@lguohan @lihuay @saiarcot895 need help with the review for this

lihuay
lihuay previously approved these changes Mar 3, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a jinja2.exceptions.UndefinedError that occurs when IPv6 is disabled on a subinterface in the show_interface.j2 CLI renderer template. When IPv6 is disabled, the openconfig-if-ip:ipv6 object can exist but without an addresses field inside it. The template was checking only for the existence of the outer IPv6 object before directly accessing its addresses field, causing a crash.

Changes:

  • Adds an "addresses" in subif["openconfig-if-ip:ipv6"] guard to the IPv6 block condition in show_interface.j2, preventing the UndefinedError when IPv6 is present but has no addresses.

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 <sumalatha.g@xoriant.com>
@mssonicbld
Copy link

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Sumalatha-G-ML Sumalatha-G-ML requested a review from lihuay March 3, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants