Skip to content

Commit 23ea50c

Browse files
authored
Merge pull request #1319 from Sage-Bionetworks/synpy-1770
[SYNPY-1770] fix variable mutation in get_conditional_properties
2 parents fcf371f + cdf116f commit 23ea50c

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

synapseclient/extensions/curator/schema_generation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,6 +4994,7 @@ def get_conditional_properties(
49944994
if self.current_node is None:
49954995
raise ValueError("Current node is None")
49964996
conditional_properties: list[tuple[str, str]] = []
4997+
49974998
for value in self._reverse_dependencies[self.current_node.name]:
49984999
if value in self._valid_values_map:
49995000
properties = sorted(self._valid_values_map[value])
@@ -5002,8 +5003,14 @@ def get_conditional_properties(
50025003
watched_property = self.dmge.get_nodes_display_names(
50035004
[watched_property]
50045005
)[0]
5005-
value = self.dmge.get_nodes_display_names([value])[0]
5006-
conditional_properties.append((watched_property, value))
5006+
display_name_value = self.dmge.get_nodes_display_names([value])[
5007+
0
5008+
]
5009+
conditional_properties.append(
5010+
(watched_property, display_name_value)
5011+
)
5012+
else:
5013+
conditional_properties.append((watched_property, value))
50075014
return conditional_properties
50085015

50095016
def _update_valid_values_map(

tests/unit/synapseclient/extensions/unit_test_create_json_schema.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,32 @@ def test_get_conditional_properties(self, dmge: DataModelGraphExplorer) -> None:
845845
# THEN the current node should have conditional properties
846846
assert gts.get_conditional_properties() == [("Diagnosis", "Cancer")]
847847

848+
def test_get_conditional_properties_multiple_watched_properties(
849+
self, dmge: DataModelGraphExplorer
850+
) -> None:
851+
"""Test GraphTraversalState.get_conditional_properties with multiple watched properties.
852+
853+
This test covers a bug where the 'value' variable was being mutated inside
854+
the inner loop when converting to display names.
855+
856+
"""
857+
# GIVEN a GraphTraversalState instance where
858+
# - CancerType has a reverse dependency of FamilyHistory
859+
# - FamilyHistory is a valid value of MULTIPLE attributes
860+
gts = GraphTraversalState(dmge, "Patient", logger=Mock())
861+
gts._nodes_to_process = ["CancerType"]
862+
863+
# Use FamilyHistory because its display name ("Family History") differs from class label
864+
gts._reverse_dependencies = {"CancerType": ["FamilyHistory"]}
865+
# FamilyHistory triggers multiple watched properties - this is key to triggering the bug
866+
gts._valid_values_map = {"FamilyHistory": ["Sex", "YearofBirth"]}
867+
# WHEN using move_to_next_node
868+
gts.move_to_next_node()
869+
result = gts.get_conditional_properties()
870+
assert len(result) == 2
871+
assert ("Year of Birth", "Family History") in result
872+
assert ("Sex", "Family History") in result
873+
848874
def test_update_valid_values_map(self, dmge: DataModelGraphExplorer) -> None:
849875
"""Test GraphTraversalState._update_valid_values_map"""
850876
# GIVEN a GraphTraversalState instance

0 commit comments

Comments
 (0)