Fix Jinja2 template error when IPv6 is disabled on subinterface#156
Open
Sumalatha-G-ML wants to merge 2 commits intosonic-net:masterfrom
Open
Fix Jinja2 template error when IPv6 is disabled on subinterface#156Sumalatha-G-ML wants to merge 2 commits intosonic-net:masterfrom
Sumalatha-G-ML wants to merge 2 commits intosonic-net:masterfrom
Conversation
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>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Author
|
@lguohan @lihuay @saiarcot895 need help with the review for this |
lihuay
previously approved these changes
Mar 3, 2026
There was a problem hiding this comment.
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 inshow_interface.j2, preventing theUndefinedErrorwhen 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>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: