Sage-Bionetworks / synapsePythonClient

Programmatic interface to Synapse services for Python
https://www.synapse.org
Apache License 2.0
67 stars 68 forks source link

[SYNPY-1443] Correct which fields are merged if there is a change #1072

Closed BryanFauble closed 7 months ago

BryanFauble commented 7 months ago

Problem:

  1. The usage of asdict was converting the folder/file dataclasses to a dict on the Project class - This pevented further code from calling methods on the Folder/File class.
    File "/home/bfauble/BryansGreatWorkspace/synapsePythonClient/synapseclient/models/project.py", line 308, in store_async
    await store_entity_components(
    File "/home/bfauble/BryansGreatWorkspace/synapsePythonClient/synapseclient/models/services/storable_entity_components.py", line 80, in store_entity_components
    folder.store_async(
    AttributeError: 'dict' object has no attribute 'store_async'

Solution:

  1. Only apply changes for modified items. We are not retrieving any dataclasses during the get_async calls during this line besides self - So we won't run into issues where a dataclass is getting replaced by a dict.
  2. If we are to retrieve dataclasses during the get_async calls we'll need to make a small modification to this code to ensure the merge occurs in that dataclass (recursively) and is converted back into the correct class instance. I will take ownership of this problem when we need to cross that bridge.

Testing:

  1. Verified the broken script works as expected:
    
    import synapseclient
    from synapseclient.models import Project, Folder, File

syn = synapseclient.login() file_for_demo = "/home/bfauble/temp/my_file_with_random_data.txt" my_project_name = "My Super Cool Project"

my_project = Project(name=my_project_name)

my_folder = Folder(name="my folder")

my_file = File(path=file_for_demo)

my_folder.files.append(my_file)

my_project.folders.append(my_folder)

my_project.store()



1. Integration test around this logic
sonarcloud[bot] commented 7 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
47.0% Duplication on New Code

See analysis details on SonarCloud