Skip to content

Commit d0c4da0

Browse files
authored
Merge pull request #433 from hubmapconsortium/Derek-Furst/prov-info-return-size
Modified datasets/prov-info and samples/prov-info to check the size o…
2 parents 1176e7e + 168c1d7 commit d0c4da0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/app.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,9 +2688,9 @@ def get_prov_info():
26882688
internal_dict[HEADER_DATASET_STATUS] = dataset['status']
26892689
internal_dict[HEADER_DATASET_GROUP_NAME] = dataset['group_name']
26902690
internal_dict[HEADER_DATASET_GROUP_UUID] = dataset['group_uuid']
2691-
internal_dict[HEADER_DATASET_DATE_TIME_CREATED] = datetime.fromtimestamp(int(dataset['created_timestamp']/1000.0))
2691+
internal_dict[HEADER_DATASET_DATE_TIME_CREATED] = str(datetime.fromtimestamp(int(dataset['created_timestamp'] / 1000.0)))
26922692
internal_dict[HEADER_DATASET_CREATED_BY_EMAIL] = dataset['created_by_user_email']
2693-
internal_dict[HEADER_DATASET_DATE_TIME_MODIFIED] = datetime.fromtimestamp(int(dataset['last_modified_timestamp']/1000.0))
2693+
internal_dict[HEADER_DATASET_DATE_TIME_MODIFIED] = str(datetime.fromtimestamp(int(dataset['last_modified_timestamp'] / 1000.0)))
26942694
internal_dict[HEADER_DATASET_MODIFIED_BY_EMAIL] = dataset['last_modified_user_email']
26952695
internal_dict[HEADER_DATASET_LAB_ID] = dataset['lab_dataset_id']
26962696

@@ -2856,6 +2856,14 @@ def get_prov_info():
28562856
# Each dataset's dictionary is added to the list to be returned
28572857
dataset_prov_list.append(internal_dict)
28582858

2859+
# Determine whether the size of the returned data exceeds or nearly exceeds the AWS Gateway 10MB maximum size. If it
2860+
# is greater than 9437184 bytes Return a 400 and prompt the user to reduce the size of the output by applying optional
2861+
# argument filters.
2862+
dataset_prov_json_encode = json.dumps(dataset_prov_list).encode('utf-8')
2863+
if len(dataset_prov_json_encode) > 9437184:
2864+
bad_request_error(
2865+
"Request generated a response over the 10MB limit. Sub-select the results using a query parameter.")
2866+
28592867
# if return_json is true, this dictionary is ready to be returned already
28602868
if return_json:
28612869
return jsonify(dataset_prov_list)
@@ -3018,10 +3026,9 @@ def get_prov_info_for_dataset(id):
30183026
internal_dict[HEADER_DATASET_STATUS] = dataset['status']
30193027
internal_dict[HEADER_DATASET_GROUP_NAME] = dataset['group_name']
30203028
internal_dict[HEADER_DATASET_GROUP_UUID] = dataset['group_uuid']
3021-
internal_dict[HEADER_DATASET_DATE_TIME_CREATED] = datetime.fromtimestamp(int(dataset['created_timestamp'] / 1000.0))
3029+
internal_dict[HEADER_DATASET_DATE_TIME_CREATED] = str(datetime.fromtimestamp(int(dataset['created_timestamp'] / 1000.0)))
30223030
internal_dict[HEADER_DATASET_CREATED_BY_EMAIL] = dataset['created_by_user_email']
3023-
internal_dict[HEADER_DATASET_DATE_TIME_MODIFIED] = datetime.fromtimestamp(
3024-
int(dataset['last_modified_timestamp'] / 1000.0))
3031+
internal_dict[HEADER_DATASET_DATE_TIME_MODIFIED] = str(datetime.fromtimestamp(int(dataset['last_modified_timestamp'] / 1000.0)))
30253032
internal_dict[HEADER_DATASET_MODIFIED_BY_EMAIL] = dataset['last_modified_user_email']
30263033
internal_dict[HEADER_DATASET_LAB_ID] = dataset['lab_dataset_id']
30273034

@@ -3448,7 +3455,14 @@ def get_sample_prov_info():
34483455

34493456
# Each sample's dictionary is added to the list to be returned
34503457
sample_prov_list.append(internal_dict)
3451-
3458+
3459+
# Determine whether the size of the returned data exceeds or nearly exceeds the AWS Gateway 10MB maximum size. If it
3460+
# is greater than 9437184 bytes Return a 400 and prompt the user to reduce the size of the output by applying optional
3461+
# argument filters.
3462+
sample_prov_json_encode = json.dumps(sample_prov_list).encode('utf-8')
3463+
if len(sample_prov_json_encode) > 9437184:
3464+
bad_request_error(
3465+
"Request generated a response over the 10MB limit. Sub-select the results using a query parameter.")
34523466
return jsonify(sample_prov_list)
34533467

34543468

0 commit comments

Comments
 (0)