Skip to content

Commit 199cc90

Browse files
authored
Merge pull request #919 from hubmapconsortium/yuanzhou/reindex-component-status
Don't run after_create and after_update triggers if not specified
2 parents f14a341 + 89dfd35 commit 199cc90

File tree

3 files changed

+262
-164
lines changed

3 files changed

+262
-164
lines changed

src/app.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ def create_entity(entity_type):
12041204
# For Dataset: link to direct ancestors
12051205
# For Collection: link to member Datasets
12061206
# For Upload: link to parent Lab node
1207-
after_create(normalized_entity_type, request, user_token, merged_dict)
1207+
after_create(normalized_entity_type, request, user_token, merged_dict, json_data_dict)
12081208

12091209
# By default we'll return all the properties but skip these time-consuming ones
12101210
# Donor doesn't need to skip any
@@ -1451,12 +1451,12 @@ def update_entity(id):
14511451
if direct_ancestor_dict['entity_type'] not in ['Donor', 'Sample']:
14521452
bad_request_error(f"The uuid: {direct_ancestor_uuid} is not a Donor neither a Sample, cannot be used as the direct ancestor of this Sample")
14531453

1454-
# Generate 'before_update_triiger' data and update the entity details in Neo4j
1454+
# Generate 'before_update_trigger' data and update the entity details in Neo4j
14551455
merged_updated_dict = update_entity_details(request, normalized_entity_type, user_token, json_data_dict, entity_dict)
14561456

14571457
# Handle linkages update via `after_update_trigger` methods
14581458
if has_direct_ancestor_uuid:
1459-
after_update(normalized_entity_type, request, user_token, merged_updated_dict)
1459+
after_update(normalized_entity_type, request, user_token, merged_updated_dict, json_data_dict)
14601460
# 2/17/23 - Adding direct ancestor checks to publication as well as dataset.
14611461
elif normalized_entity_type in ['Dataset', 'Publication']:
14621462
# A bit more validation if `direct_ancestor_uuids` provided
@@ -1485,7 +1485,7 @@ def update_entity(id):
14851485

14861486
# Handle linkages update via `after_update_trigger` methods
14871487
if has_direct_ancestor_uuids or has_associated_collection_uuid or has_updated_status:
1488-
after_update(normalized_entity_type, request, user_token, merged_updated_dict)
1488+
after_update(normalized_entity_type, request, user_token, merged_updated_dict, json_data_dict)
14891489
elif normalized_entity_type == 'Upload':
14901490
has_dataset_uuids_to_link = False
14911491
if ('dataset_uuids_to_link' in json_data_dict) and (json_data_dict['dataset_uuids_to_link']):
@@ -1500,13 +1500,13 @@ def update_entity(id):
15001500

15011501
# Handle linkages update via `after_update_trigger` methods
15021502
if has_dataset_uuids_to_link or has_dataset_uuids_to_unlink or has_updated_status:
1503-
after_update(normalized_entity_type, request, user_token, merged_updated_dict)
1503+
after_update(normalized_entity_type, request, user_token, merged_updated_dict, json_data_dict)
15041504
elif schema_manager.entity_type_instanceof(normalized_entity_type, 'Collection'):
15051505
# Generate 'before_update_trigger' data and update the entity details in Neo4j
15061506
merged_updated_dict = update_entity_details(request, normalized_entity_type, user_token, json_data_dict, entity_dict)
15071507

15081508
# Handle linkages update via `after_update_trigger` methods
1509-
after_update(normalized_entity_type, request, user_token, merged_updated_dict)
1509+
after_update(normalized_entity_type, request, user_token, merged_updated_dict, json_data_dict)
15101510
else:
15111511
# Generate 'before_update_trigger' data and update the entity details in Neo4j
15121512
merged_updated_dict = update_entity_details(request, normalized_entity_type, user_token, json_data_dict, entity_dict)
@@ -4580,7 +4580,7 @@ def _get_dataset_associated_metadata(dataset_dict, dataset_visibility, valid_use
45804580

45814581

45824582
"""
4583-
Generate 'before_create_triiger' data and create the entity details in Neo4j
4583+
Generate 'before_create_trigger' data and create the entity details in Neo4j
45844584
45854585
Parameters
45864586
----------
@@ -5000,7 +5000,7 @@ def create_multiple_component_details(request, normalized_entity_type, user_toke
50005000

50015001

50025002
"""
5003-
Execute 'after_create_triiger' methods
5003+
Execute 'after_create_trigger' methods
50045004
50055005
Parameters
50065006
----------
@@ -5013,8 +5013,10 @@ def create_multiple_component_details(request, normalized_entity_type, user_toke
50135013
merged_data_dict: dict
50145014
The merged dict that contains the entity dict newly created and
50155015
information from user request json that are not stored in Neo4j
5016+
json_data_dict: dict
5017+
The json request dict
50165018
"""
5017-
def after_create(normalized_entity_type, request, user_token, merged_data_dict):
5019+
def after_create(normalized_entity_type, request, user_token, merged_data_dict, json_data_dict):
50185020
try:
50195021
# 'after_create_trigger' and 'after_update_trigger' don't generate property values
50205022
# It just returns the empty dict, no need to assign value
@@ -5024,7 +5026,7 @@ def after_create(normalized_entity_type, request, user_token, merged_data_dict):
50245026
, request=request
50255027
, user_token=user_token
50265028
, existing_data_dict=merged_data_dict
5027-
, new_data_dict={})
5029+
, new_data_dict=json_data_dict)
50285030
except schema_errors.AfterCreateTriggerException:
50295031
# Log the full stack trace, prepend a line with our message
50305032
msg = "The entity has been created, but failed to execute one of the 'after_create_trigger' methods"
@@ -5036,7 +5038,7 @@ def after_create(normalized_entity_type, request, user_token, merged_data_dict):
50365038

50375039

50385040
"""
5039-
Generate 'before_create_triiger' data and create the entity details in Neo4j
5041+
Generate 'before_create_trigger' data and create the entity details in Neo4j
50405042
50415043
Parameters
50425044
----------
@@ -5133,20 +5135,19 @@ def update_entity_details(request, normalized_entity_type, user_token, json_data
51335135
The instance of Flask request passed in from application request
51345136
user_token: str
51355137
The user's globus groups token
5136-
entity_dict: dict
5137-
The entity dict newly updated
5138+
merged_updated_dict: dict
5139+
The merged entity dict containing newly updated values and existing values
5140+
json_data_dict: dict
5141+
The data dict containing new values
51385142
"""
5139-
def after_update(normalized_entity_type, request, user_token, entity_dict):
5143+
def after_update(normalized_entity_type, request, user_token, merged_updated_dict, json_data_dict):
51405144
try:
5141-
# 'after_create_trigger' and 'after_update_trigger' don't generate property values
5142-
# It just returns the empty dict, no need to assign value
5143-
# Use {} sicne no new dict
51445145
schema_manager.generate_triggered_data( trigger_type=TriggerTypeEnum.AFTER_UPDATE
51455146
, normalized_class=normalized_entity_type
51465147
, request=request
51475148
, user_token=user_token
5148-
, existing_data_dict=entity_dict
5149-
, new_data_dict={})
5149+
, existing_data_dict=merged_updated_dict
5150+
, new_data_dict=json_data_dict)
51505151
except schema_errors.AfterUpdateTriggerException:
51515152
# Log the full stack trace, prepend a line with our message
51525153
msg = "The entity information has been updated, but failed to execute one of the 'after_update_trigger' methods"

src/schema/schema_manager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ def generate_triggered_data(trigger_type: TriggerTypeEnum, normalized_class, req
410410
if trigger_type in [TriggerTypeEnum.AFTER_CREATE, TriggerTypeEnum.AFTER_UPDATE]:
411411
# Only call the triggers if the propery key presents from the incoming data
412412
# E.g., 'direct_ancestor_uuid' for Sample, 'dataset_uuids' for Collection
413-
# This `existing_data_dict` is the newly created or updated entity dict
414-
if key in existing_data_dict:
413+
if key in new_data_dict:
415414
trigger_method_name = properties[key][trigger_type.value]
416415

417416
try:
@@ -423,8 +422,7 @@ def generate_triggered_data(trigger_type: TriggerTypeEnum, normalized_class, req
423422
# No return values for 'after_create_trigger' and 'after_update_trigger'
424423
# because the property value is already set and stored in neo4j
425424
# Normally it's building linkages between entity nodes
426-
# Use {} since no incoming new_data_dict
427-
trigger_method_to_call(key, normalized_class, request, user_token, existing_data_dict, {})
425+
trigger_method_to_call(key, normalized_class, request, user_token, existing_data_dict, new_data_dict)
428426
except Exception:
429427
msg = f"Failed to call the {trigger_type.value} method: {trigger_method_name}"
430428
# Log the full stack trace, prepend a line with our message

0 commit comments

Comments
 (0)