Skip to content

Commit b042caf

Browse files
committed
Merge branch 'fix/failed-to-get-document-details' into 'develop'
Fix/failed to get document details See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!309
2 parents ad98577 + 43d3f98 commit b042caf

File tree

5 files changed

+637
-113
lines changed

5 files changed

+637
-113
lines changed

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ SPDX-License-Identifier: MIT-0
66
## [Unreleased]
77

88
### Fixed
9-
- **GovCloud Template Generation - CloudFront Policy Removal**
10-
- Fixed issue where CloudFront policy statements were still appearing in generated GovCloud templates despite CloudFront resources being removed
11-
- **Duplicate Glue tables created when dash used in document class name**
12-
- Duplicate Glue tables are created when using a document class that contains a dash (-). Resolved by replacing dash in section types with underscore character when creating the table, to align with the table name generated later by the Glue crawler - resolves #57.
9+
- Fixed issue where CloudFront policy statements were still appearing in generated GovCloud templates despite CloudFront resources being removed
10+
- Fix duplicate Glue tables are created when using a document class that contains a dash (-). Resolved by replacing dash in section types with underscore character when creating the table, to align with the table name generated later by the Glue crawler - resolves #57.
11+
- Fix occasional UI error 'Failed to get document details - please try again later' - resolves #58
1312

1413
## [0.3.15]
1514

src/lambda/create_document_resolver/index.py

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88
from decimal import Decimal
9-
import datetime
9+
from robust_list_deletion import delete_list_entries_robust, calculate_shard
1010

1111
# Configure logging
1212
logger = logging.getLogger()
@@ -28,8 +28,18 @@ def handler(event, context):
2828
try:
2929
# Extract input data from full AppSync context
3030
input_data = event['arguments']['input']
31-
object_key = input_data['ObjectKey']
32-
queued_time = input_data['QueuedTime']
31+
32+
# Validate required input fields
33+
if not input_data:
34+
raise ValueError("Input data is required")
35+
36+
object_key = input_data.get('ObjectKey')
37+
queued_time = input_data.get('QueuedTime')
38+
39+
if not object_key or not isinstance(object_key, str):
40+
raise ValueError("ObjectKey must be a non-empty string")
41+
if not queued_time or not isinstance(queued_time, str):
42+
raise ValueError("QueuedTime must be a non-empty string")
3343

3444
logger.info(f"Processing document: {object_key}, QueuedTime: {queued_time}")
3545

@@ -57,52 +67,22 @@ def handler(event, context):
5767
logger.error(f"Error checking for existing document: {str(e)}")
5868
# Continue with creation process even if this check fails
5969

60-
# If existing document found, delete its list entry
61-
if existing_doc and 'QueuedTime' in existing_doc:
70+
# If existing document found, delete its list entry using robust deletion
71+
if existing_doc:
6272
try:
63-
old_time = existing_doc['QueuedTime']
64-
logger.info(f"Deleting list entry for existing document with QueuedTime: {old_time}")
65-
66-
# Calculate shard ID for the old list entry
67-
old_date = old_time.split('T')[0] # e.g., 2023-01-01
68-
old_hour = int(old_time.split('T')[1].split(':')[0]) # e.g., 12
69-
70-
# Calculate shard (6 shards per day = 4 hours each)
71-
shards_in_day = 6
72-
hours_in_shard = 24 / shards_in_day
73-
old_shard = int(old_hour / hours_in_shard)
74-
old_shard_str = f"{old_shard:02d}" # Format with leading zero
73+
logger.info(f"Attempting robust deletion of list entries for existing document: {object_key}")
74+
deletion_success = delete_list_entries_robust(tracking_table, object_key, existing_doc)
7575

76-
old_list_pk = f"list#{old_date}#s#{old_shard_str}"
77-
old_list_sk = f"ts#{old_time}#id#{object_key}"
78-
79-
logger.info(f"Deleting list entry with PK={old_list_pk}, SK={old_list_sk}")
80-
result = tracking_table.delete_item(
81-
Key={
82-
'PK': old_list_pk,
83-
'SK': old_list_sk
84-
},
85-
ReturnValues='ALL_OLD'
86-
)
87-
88-
if 'Attributes' in result:
89-
logger.info(f"Successfully deleted list entry: {json.dumps(result['Attributes'], cls=DecimalEncoder)}")
76+
if deletion_success:
77+
logger.info(f"Successfully deleted existing list entries for {object_key}")
9078
else:
91-
logger.warning(f"No list entry found to delete with PK={old_list_pk}, SK={old_list_sk}")
79+
logger.warning(f"No existing list entries found/deleted for {object_key}")
9280
except Exception as e:
93-
logger.error(f"Error deleting list entry: {str(e)}")
81+
logger.error(f"Error in robust list entry deletion: {str(e)}")
9482
# Continue with creation process even if deletion fails
9583

96-
# Calculate shard ID for new list entry
97-
date_part = queued_time.split('T')[0] # e.g., 2023-01-01
98-
hour_part = int(queued_time.split('T')[1].split(':')[0]) # e.g., 12
99-
100-
# Calculate shard (6 shards per day = 4 hours each)
101-
shards_in_day = 6
102-
hours_in_shard = 24 / shards_in_day
103-
shard = int(hour_part / hours_in_shard)
104-
shard_str = f"{shard:02d}" # Format with leading zero
105-
84+
# Calculate shard ID for new list entry using shared utility
85+
date_part, shard_str = calculate_shard(queued_time)
10686
list_pk = f"list#{date_part}#s#{shard_str}"
10787
list_sk = f"ts#{queued_time}#id#{object_key}"
10888

@@ -140,4 +120,4 @@ def handler(event, context):
140120
return {"ObjectKey": object_key}
141121
except Exception as e:
142122
logger.error(f"Error in create_document resolver: {str(e)}", exc_info=True)
143-
raise e
123+
raise e

0 commit comments

Comments
 (0)