Skip to content

Commit 3306f65

Browse files
authored
Merge pull request #681 from atlanhq/APP-7697
APP-7697 : custom metadata object created via Python
2 parents b995816 + b5e1018 commit 3306f65

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pyatlan/model/typedef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class Options(AtlanObject):
504504

505505
def __setattr__(self, name, value):
506506
super().__setattr__(name, value)
507-
if self._attr_def and name == "multi_value_select":
507+
if self._attr_def and name == "multi_value_select" and value is True:
508508
self._attr_def.cardinality = Cardinality.SET
509509
if self._attr_def.type_name and "array<" not in str(
510510
self._attr_def.type_name

tests/unit/test_typedef_model.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pyatlan.model.typedef import (
1717
AtlanTagDef,
1818
AttributeDef,
19+
Cardinality,
1920
CustomMetadataDef,
2021
EntityDef,
2122
EnumDef,
@@ -443,3 +444,33 @@ def test_attribute_create_with_limited_applicability(self, client: AtlanClient):
443444
assert getattr(options, attribute) == json.dumps(
444445
list(applicable_kwargs.get(attribute)) # type: ignore[arg-type]
445446
)
447+
448+
def test_multi_value_select_setter_condition(self, client: AtlanClient):
449+
with patch("pyatlan.model.typedef._get_all_qualified_names") as mock_get_qa:
450+
mock_get_qa.return_value = set()
451+
452+
attr_def = AttributeDef.create(
453+
client=client,
454+
display_name="Test Attribute",
455+
attribute_type=AtlanCustomAttributePrimitiveType.STRING,
456+
)
457+
458+
assert attr_def.options is not None
459+
assert attr_def.options.multi_value_select is False
460+
assert attr_def.cardinality == Cardinality.SINGLE
461+
assert attr_def.type_name == AtlanCustomAttributePrimitiveType.STRING.value
462+
463+
# Test 1: Setting multi_value_select to False should NOT trigger __setattr__ logic
464+
attr_def.options.multi_value_select = False
465+
466+
assert attr_def.cardinality == Cardinality.SINGLE
467+
assert attr_def.type_name == AtlanCustomAttributePrimitiveType.STRING.value
468+
469+
# Test 2: Setting multi_value_select to True should trigger __setattr__ logic
470+
attr_def.options.multi_value_select = True
471+
472+
assert attr_def.cardinality == Cardinality.SET
473+
assert (
474+
attr_def.type_name
475+
== f"array<{AtlanCustomAttributePrimitiveType.STRING.value}>"
476+
)

0 commit comments

Comments
 (0)