Skip to content

Commit 833748d

Browse files
committed
fix dictionary value extraction issue
1 parent 45990b3 commit 833748d

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

synapseclient/models/services/migration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ def _escape_column_name(column: Union[str, collections.abc.Mapping]) -> str:
144144
from synapseclient.models import Column
145145

146146
col_name = (
147-
column.name
148-
if (isinstance(column, collections.abc.Mapping) or isinstance(column, Column))
147+
column["name"]
148+
if isinstance(column, collections.abc.Mapping)
149+
else column.name
150+
if isinstance(column, Column)
149151
else str(column)
150152
)
151153
escaped_name = col_name.replace('"', '""')

tests/unit/synapseclient/services/unit_test_migration_and_types_async.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,24 +1727,21 @@ async def test_file_handle_columns_yields_rows(self):
17271727
client = _make_mock_client()
17281728
col = MagicMock()
17291729
col.column_type = "FILEHANDLEID"
1730-
col.__getitem__ = MagicMock(
1731-
side_effect=lambda k: "col_42" if k == "id" else None
1732-
)
17331730
col.id = "col_42"
17341731

17351732
fh = _make_file_handle()
17361733

17371734
# Row: [row_id, row_version, file_handle_id]
1738-
query_results = [[1, 2, "fh_abc"]]
1735+
mock_results = MagicMock()
1736+
mock_results.iterrows.return_value = iter([(0, [1, 2, "fh_abc"])])
1737+
1738+
mock_table_instance = MagicMock()
1739+
mock_table_instance.query_async = AsyncMock(return_value=mock_results)
1740+
mock_table_class = MagicMock(return_value=mock_table_instance)
17391741

1740-
# query_async is TYPE_CHECKING-only import so patch requires create=True
17411742
with (
17421743
patch(f"{MODULE}.get_columns", new=AsyncMock(return_value=[col])),
1743-
patch(
1744-
f"{MODULE}.query_async",
1745-
new=AsyncMock(return_value=query_results),
1746-
create=True,
1747-
),
1744+
patch("synapseclient.models.Table", mock_table_class),
17481745
patch(
17491746
f"{MODULE}.get_file_handle_for_download_async",
17501747
new=AsyncMock(return_value={"fileHandle": fh}),
@@ -2110,8 +2107,7 @@ async def test_sets_file_handle_and_stores(self):
21102107
to_file_handle_id="fh_new",
21112108
synapse_client=client,
21122109
)
2113-
2114-
assert entity.dataFileHandleId == "fh_new"
2110+
assert entity.data_file_handle_id == "fh_new"
21152111
entity.store_async.assert_awaited_once()
21162112

21172113

0 commit comments

Comments
 (0)