-
Notifications
You must be signed in to change notification settings - Fork 72
[SYNPY-1437] INCOMPLETE/DRAFT - Start the process to move to use the /bundle2 rest API #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
BryanFauble
wants to merge
1
commit into
develop
Choose a base branch
from
synpy-1437-use-bundle2-service
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,3 +152,92 @@ async def put_entity_id_bundle2( | |
+ (f"?generatedBy={generated_by}" if generated_by else ""), | ||
body=json.dumps(request), | ||
) | ||
|
||
|
||
async def store_entity_with_bundle2( | ||
entity: Dict[str, Any], | ||
parent_id: Optional[str] = None, | ||
acl: Optional[Dict[str, Any]] = None, # TODO: Consider skipping ACL? | ||
annotations: Optional[Dict[str, Any]] = None, | ||
activity: Optional[Dict[str, Any]] = None, | ||
new_version: bool = False, | ||
force_version: bool = False, | ||
*, | ||
synapse_client: Optional["Synapse"] = None, | ||
) -> Dict[str, Any]: | ||
""" | ||
Store an entity in Synapse using the bundle2 API endpoints to reduce HTTP calls. | ||
|
||
This function follows a specific flow: | ||
1. Determines if the operation is a create or update: | ||
- If no ID is provided, searches for the ID via /entity/child | ||
- If no ID is found, treats as a Create | ||
- If an ID is found, treats as an Update | ||
|
||
2. For Updates: | ||
- Retrieves entity by ID and merges with existing data | ||
- Updates desired fields in the retrieved object | ||
- Pushes modified object with HTTP PUT if there are changes | ||
|
||
3. For Creates: | ||
- Creates a new object with desired fields | ||
- Pushes the new object with HTTP POST | ||
|
||
Arguments: | ||
entity: The entity to store. | ||
parent_id: The ID of the parent entity for creation. | ||
acl: Access control list for the entity. | ||
annotations: Annotations to associate with the entity. | ||
activity: Activity to associate with the entity. | ||
new_version: If True, create a new version of the entity. | ||
force_version: If True, forces a new version of an entity even if nothing has changed. | ||
synapse_client: Synapse client instance. | ||
|
||
Returns: | ||
The stored entity bundle. | ||
""" | ||
from synapseclient import Synapse | ||
|
||
client = Synapse.get_client(synapse_client=synapse_client) | ||
|
||
# Determine if this is a create or update operation | ||
entity_id = entity.get("id", None) | ||
|
||
# Construct bundle request based on provided data | ||
bundle_request = {"entity": entity} | ||
|
||
if annotations: | ||
bundle_request["annotations"] = annotations | ||
|
||
if acl: | ||
bundle_request["accessControlList"] = acl | ||
|
||
if activity: | ||
bundle_request["activity"] = activity | ||
|
||
# Handle create or update | ||
if not entity_id: | ||
# This is a creation | ||
client.logger.debug("Creating new entity via bundle2 API") | ||
|
||
# For creation, parent ID is required | ||
# TODO: Projects won't have a parent in this case | ||
# if parent_id: | ||
# # Add parentId to the entity if not already set | ||
# if not entity.get("parentId"): | ||
# entity["parentId"] = parent_id | ||
# elif not entity.get("parentId"): | ||
# raise ValueError("Parent ID must be provided for entity creation") | ||
|
||
# Create entity using bundle2 create endpoint | ||
return await post_entity_bundle2_create( | ||
request=bundle_request, | ||
generated_by=activity.get("id") if activity else None, | ||
synapse_client=synapse_client, | ||
) | ||
else: | ||
# This is an update | ||
client.logger.debug(f"Updating entity {entity_id} via bundle2 API") | ||
|
||
# For updates we might need to retrieve the existing entity to merge data | ||
# Only retrieve if we need | ||
Comment on lines
+242
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update functionality is incomplete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be addressed