Skip to content

Commit 0ca1ec5

Browse files
committed
Merge branch 'boolean-null-default' into 'main'
Compare null-default boolean values correctly during discovery See merge request weblogic-cloud/weblogic-deploy-tooling!1529
2 parents 4eda897 + d2c1ddb commit 0ca1ec5

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

core/src/main/python/wlsdeploy/aliases/aliases.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,10 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
10911091
model_attribute_value = PASSWORD_TOKEN
10921092

10931093
elif model_type == 'boolean':
1094-
wlst_val = alias_utils.convert_boolean(converted_value)
1095-
default_val = alias_utils.convert_boolean(default_value)
1096-
if wlst_val == default_val:
1094+
# some boolean attributes have WLST value of null until they are set
1095+
wlst_boolean = _get_boolean_or_none(wlst_attribute_value) # from unconverted value
1096+
default_boolean = _get_boolean_or_none(default_value)
1097+
if wlst_boolean == default_boolean:
10971098
model_attribute_value = None
10981099
else:
10991100
model_attribute_value = converted_value
@@ -1591,3 +1592,14 @@ def _strings_are_empty(converted_value, default_value):
15911592
str_default_value = None
15921593

15931594
return string_utils.is_empty(str_converted_value) and string_utils.is_empty(str_default_value)
1595+
1596+
1597+
def _get_boolean_or_none(attribute_value):
1598+
"""
1599+
Return the boolean value of the specified value, or None if it is None.
1600+
This is needed to match boolean WLST attributes that are null until they are set.
1601+
:param attribute_value: the value to convert to boolean or None
1602+
"""
1603+
if attribute_value is None:
1604+
return None
1605+
return alias_utils.convert_boolean(attribute_value)

core/src/test/python/aliases_test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -350,23 +350,23 @@ def testGetWlstAttributeNameAndValue(self):
350350
def testGetModelAttributeNameAndValue(self):
351351
location = get_jdbc_ds_params_location('my-datasource', self.aliases)
352352

353-
# get model attribute value should return the value only if its NOT the default
354-
boolean_values = ['false', None]
353+
# get model attribute value should return the value only if it's NOT the default
354+
boolean_values = ['false', False]
355355
wlst_attribute_name = 'RowPrefetch'
356356
wlst_attribute_value = boolean_values[0]
357357
model_attribute_name, model_attribute_value = \
358358
self.aliases.get_model_attribute_name_and_value(location, wlst_attribute_name, wlst_attribute_value)
359-
self.assertEqual(model_attribute_value, boolean_values[1])
359+
self.assertEqual(bool(model_attribute_value), boolean_values[1])
360360

361-
# get model attribute value should return the value only if its NOT the default
361+
# get model attribute value should return the value only if it's NOT the default
362362
string_value = [None, None]
363363
wlst_attribute_name = 'RowPrefetchSize'
364364
wlst_attribute_value = string_value[0]
365365
model_attribute_name, model_attribute_value = \
366366
self.aliases.get_model_attribute_name_and_value(location, wlst_attribute_name, wlst_attribute_value)
367367
self.assertEqual(model_attribute_value, string_value[1])
368368

369-
# get model attribute value should return the value only if its NOT the default
369+
# get model attribute value should return the value only if it's NOT the default
370370
location = LocationContext()
371371
location.append_location(FOLDERS.SERVER)
372372
boolean_values = [0, None]

0 commit comments

Comments
 (0)