Prevent ValueError on split_message function

This commit improves the robustness of the 'split_message' function
by handling the 'AttributeError' exception. It ensures that the
function returns a list with a single element containing 'value' when
splitting is not possible, thereby preventing 'ValueError' issues.

Test Plan: WIP
Closes-Bug: WIP

Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
Change-Id: Ib0cc834ee67e29c7cc486060d1b42be5a928bc49
This commit is contained in:
Enzo Candotti 2023-10-24 16:34:31 -03:00
parent ac9d905754
commit 4621e362f6
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,33 @@
From be4910f7477913f7543aede63c435e5f4ef14c38 Mon Sep 17 00:00:00 2001
From: Enzo Candotti <enzo.candotti@windriver.com>
Date: Mon, 23 Oct 2023 14:44:26 -0300
Subject: [PATCH] Prevent ValueError on split_message function
This commit improves the robustness of the 'split_message' function
by handling the 'AttributeError' exception. It ensures that the
function returns a list with a single element containing 'value' when
splitting is not possible, thereby preventing 'ValueError' issues.
Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
---
horizon/templatetags/splitfilter.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/horizon/templatetags/splitfilter.py b/horizon/templatetags/splitfilter.py
index 7d5d497c7..1a598d373 100644
--- a/horizon/templatetags/splitfilter.py
+++ b/horizon/templatetags/splitfilter.py
@@ -19,4 +19,8 @@ register = template.Library()
@register.filter(name='split_message')
def split_message(value):
- return value.split(exceptions.SEPARATOR)
+ try:
+ return value.split(exceptions.SEPARATOR)
+ except AttributeError:
+ # If it cannot be split, return a list with a single element containing 'value'.
+ return [value]
\ No newline at end of file
--
2.25.1

View File

@ -1,3 +1,4 @@
0001-Use-policy_rules-for-user-role-assignment-and-group-tabs.patch
0002-Fix-incomplete-pop-up-message-on-delete-Action.patch
0003-List-default-Address-pools-row-actions-as-disabled.patch
0004-Prevent-ValueError-on-split_message-function.patch