Skip to content

Commit e7b5b02

Browse files
authored
[SYNPY-1426] Deprecate move method (#1219)
* Deprecate move method in Synapse class with migration guidance to new dataclass models
1 parent d832dba commit e7b5b02

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

synapseclient/client.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,8 +1830,18 @@ def _getFromFile(
18301830

18311831
return bundle
18321832

1833+
@deprecated(
1834+
version="4.9.0",
1835+
reason="To be removed in 5.0.0. "
1836+
"This method uses legacy Entity objects. "
1837+
"Use the new dataclass models (File, Folder, Table, etc.) with their `parent_id` attribute and `.store()` method instead. ",
1838+
)
18331839
def move(self, entity, new_parent):
18341840
"""
1841+
**Deprecated with replacement.** This method will be removed in 5.0.0.
1842+
Use the new dataclass models (File, Folder, Table, etc.) with their `parent_id`
1843+
attribute and `.store()` method instead.
1844+
18351845
Move a Synapse entity to a new container.
18361846
18371847
Arguments:
@@ -1841,10 +1851,79 @@ def move(self, entity, new_parent):
18411851
Returns:
18421852
The Synapse Entity object that has been moved.
18431853
1844-
Example: Using this function
1854+
Example: Using this function (DEPRECATED)
18451855
Move a Synapse Entity object to a new parent container
18461856
18471857
entity = syn.move('syn456', 'syn123')
1858+
1859+
Example: Migration to new method
1860+
 
1861+
1862+
```python
1863+
from synapseclient import Synapse
1864+
from synapseclient.models import (
1865+
File, Folder, Table, Dataset, DatasetCollection,
1866+
EntityView, SubmissionView, MaterializedView, VirtualTable
1867+
)
1868+
1869+
# Login to Synapse
1870+
syn = Synapse()
1871+
syn.login()
1872+
1873+
# Moving a File
1874+
file = File(id="syn456", download_file=False).get()
1875+
file.parent_id = "syn123"
1876+
file = file.store()
1877+
print(f"Moved file to: {file.parent_id}")
1878+
1879+
# Moving a Folder
1880+
folder = Folder(id="syn789").get()
1881+
folder.parent_id = "syn123"
1882+
folder = folder.store()
1883+
print(f"Moved folder to: {folder.parent_id}")
1884+
1885+
# Moving a Table
1886+
table = Table(id="syn101112").get()
1887+
table.parent_id = "syn123"
1888+
table = table.store()
1889+
print(f"Moved table to: {table.parent_id}")
1890+
1891+
# Moving a Dataset
1892+
dataset = Dataset(id="syn131415").get()
1893+
dataset.parent_id = "syn123"
1894+
dataset = dataset.store()
1895+
print(f"Moved dataset to: {dataset.parent_id}")
1896+
1897+
# Moving a DatasetCollection
1898+
dataset_collection = DatasetCollection(id="syn161718").get()
1899+
dataset_collection.parent_id = "syn123"
1900+
dataset_collection = dataset_collection.store()
1901+
print(f"Moved dataset collection to: {dataset_collection.parent_id}")
1902+
1903+
# Moving an EntityView
1904+
entity_view = EntityView(id="syn192021").get()
1905+
entity_view.parent_id = "syn123"
1906+
entity_view = entity_view.store()
1907+
print(f"Moved entity view to: {entity_view.parent_id}")
1908+
1909+
# Moving a SubmissionView
1910+
submission_view = SubmissionView(id="syn222324").get()
1911+
submission_view.parent_id = "syn123"
1912+
submission_view = submission_view.store()
1913+
print(f"Moved submission view to: {submission_view.parent_id}")
1914+
1915+
# Moving a MaterializedView
1916+
materialized_view = MaterializedView(id="syn252627").get()
1917+
materialized_view.parent_id = "syn123"
1918+
materialized_view = materialized_view.store()
1919+
print(f"Moved materialized view to: {materialized_view.parent_id}")
1920+
1921+
# Moving a VirtualTable
1922+
virtual_table = VirtualTable(id="syn282930").get()
1923+
virtual_table.parent_id = "syn123"
1924+
virtual_table = virtual_table.store()
1925+
print(f"Moved virtual table to: {virtual_table.parent_id}")
1926+
```
18481927
"""
18491928

18501929
entity = self.get(entity, downloadFile=False)

synapseclient/models/virtualtable.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ async def store_async(
518518
ValueError: If the defining_sql contains JOIN or UNION operations,
519519
which are not supported in VirtualTables.
520520
521+
Raises:
522+
ValueError: If the defining_sql attribute is not set.
523+
521524
Example: Create a new virtual table with a defining SQL query.
522525
 
523526
@@ -553,6 +556,10 @@ async def main():
553556
"VirtualTables do not support JOIN or UNION operations in the defining_sql. "
554557
"If you need to combine data from multiple tables, consider using a MaterializedView instead."
555558
)
559+
else:
560+
raise ValueError(
561+
"The defining_sql attribute must be set for a VirtualTable."
562+
)
556563

557564
return await super().store_async(
558565
dry_run=dry_run, job_timeout=job_timeout, synapse_client=synapse_client

tests/integration/synapseclient/models/async/test_virtualtable_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ async def test_virtual_table_creation_validation(
3131

3232
# WHEN/THEN: Empty SQL should be rejected
3333
with pytest.raises(
34-
SynapseHTTPError,
35-
match="400 Client Error: The definingSQL of the virtual table is required and must not be the empty string.",
34+
ValueError,
35+
match="The defining_sql attribute must be set for a",
3636
):
3737
await empty_sql_virtual_table.store_async(synapse_client=self.syn)
3838

tests/integration/synapseclient/models/synchronous/test_virtualtable.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ async def test_virtual_table_validation_scenarios(
4747

4848
# WHEN/THEN empty SQL should be rejected
4949
with pytest.raises(
50-
SynapseHTTPError,
51-
match="400 Client Error: The definingSQL of the virtual table is required "
52-
"and must not be the empty string.",
50+
ValueError,
51+
match="The defining_sql attribute must be set for a",
5352
):
5453
empty_sql_virtual_table.store(synapse_client=self.syn)
5554

0 commit comments

Comments
 (0)