Skip to content

Commit 89ad536

Browse files
committed
Merge branch 'fix/040-assessment-unbounded-error' into 'develop'
fix: Resolve UnboundLocalError in AssessmentService initialization See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!399
2 parents 0e5dbea + 55bc4be commit 89ad536

File tree

3 files changed

+74
-17
lines changed

3 files changed

+74
-17
lines changed

CHANGELOG.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,8 @@ SPDX-License-Identifier: MIT-0
1717
- **Code Intelligence Agent**: New specialized agent for code-related assistance with DeepWiki MCP server integration, security guardrails to prevent sensitive data exposure, and user-controlled opt-in toggle (default: enabled)
1818
- **Sub-Agent Streaming**: Real-time lifecycle events (start, stream, end, error) with async generator tools, structured data detection for tables/charts, and tool usage tracking
1919
- **Rich Chat Interface**: Modern UI with CloudScape Design System featuring real-time message streaming, multi-agent support (Analytics, Code Intelligence, Error Analyzer, General), Markdown rendering with syntax highlighting, structured data visualization (charts via Chart.js, sortable tables), expandable tool usage sections, sample prompts, and auto-scroll behavior
20-
- **Enhanced User Experience**: Welcome animation, sample query suggestions, clear chat functionality, responsive mobile-friendly design, accessibility support with ARIA labels, loading states and visual feedback, error alerts with dismissible notifications
2120
- **Privacy & Security**: Explicit user consent for Code Intelligence third-party services, session isolation with unique session IDs, error boundary protection, input validation
2221

23-
### Fixed
24-
25-
- **UI Robustness for Orphaned List Entries** - [#102](https://github.com/aws-solutions-library-samples/accelerated-intelligent-document-processing-on-aws/issues/102)
26-
- Fixed UI error banner "failed to get document details - please try again later" appearing when orphaned list entries exist (list# items without corresponding doc# items in DynamoDB tracking table)
27-
- **Root Cause**: When a document had a list entry but no corresponding document record, the error would trigger UI banner and prevent display of all documents in the same time shard
28-
- **Solution**: Enhanced error handling to gracefully handle missing documents - now only shows error banner if ALL documents fail to load, not just one
29-
- **Enhanced Debugging**: Added detailed console logging with full PK/SK information for both list entries and expected document entries to facilitate cleanup of orphaned records
30-
- **User Impact**: All valid documents now display correctly even when orphaned list entries exist; debugging information available in browser console for identifying problematic entries
31-
3222
- **JSON Schema Format for Class Definitions** - [docs/json-schema-migration.md](./docs/json-schema-migration.md)
3323
- Document class definitions now use industry-standard JSON Schema Draft 2020-12 format for improved flexibility and tooling integration
3424
- **Standards-Based Validation**: Leverage standard JSON Schema validators and tooling ecosystem for better configuration validation
@@ -39,6 +29,23 @@ SPDX-License-Identifier: MIT-0
3929
- **Backward Compatible**: Legacy format remains supported through automatic migration - no manual configuration updates required
4030
- **Comprehensive Documentation**: New migration guide with format comparison, field mapping table, and best practices
4131

32+
- **Error Analyzer CloudWatch Tool Enhancements**
33+
- Enhanced CloudWatch log filtering with request ID-based filtering for more targeted error analysis
34+
- Improved XRay tool tracing and logging capabilities for better diagnostic accuracy
35+
- Enhanced error context correlation between CloudWatch logs and X-Ray traces
36+
- Consolidated and renamed tools
37+
- Provided tools access to agent
38+
- Updated system prompt
39+
40+
41+
### Fixed
42+
43+
- **UI Robustness for Orphaned List Entries** - [#102](https://github.com/aws-solutions-library-samples/accelerated-intelligent-document-processing-on-aws/issues/102)
44+
- Fixed UI error banner "failed to get document details - please try again later" appearing when orphaned list entries exist (list# items without corresponding doc# items in DynamoDB tracking table)
45+
- **Root Cause**: When a document had a list entry but no corresponding document record, the error would trigger UI banner and prevent display of all documents in the same time shard
46+
- **Solution**: Enhanced error handling to gracefully handle missing documents - now only shows error banner if ALL documents fail to load, not just one
47+
- **Enhanced Debugging**: Added detailed console logging with full PK/SK information for both list entries and expected document entries to facilitate cleanup of orphaned records
48+
- **User Impact**: All valid documents now display correctly even when orphaned list entries exist; debugging information available in browser console for identifying problematic entries
4249

4350

4451
## [0.3.21]

lib/idp_common_pkg/idp_common/assessment/service.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,22 @@ def __init__(
9393
region: AWS region for Bedrock
9494
config: Configuration dictionary or IDPConfig model
9595
"""
96-
# Convert dict to IDPConfig if needed
97-
if config is not None and isinstance(config, dict):
98-
config_model: IDPConfig = IDPConfig(**config)
99-
100-
if not isinstance(config, IDPConfig) and config is not None:
101-
config_model = IDPConfig(**config)
102-
96+
# Convert config to IDPConfig if needed
10397
if config is None:
10498
config_model = IDPConfig()
99+
elif isinstance(config, IDPConfig):
100+
config_model = config
101+
elif isinstance(config, dict):
102+
config_model = IDPConfig(**config)
103+
else:
104+
# Fallback: attempt conversion for other types
105+
try:
106+
config_model = IDPConfig(**config)
107+
except Exception as e:
108+
logger.error(f"Failed to convert config to IDPConfig: {e}")
109+
raise ValueError(
110+
f"Invalid config type: {type(config)}. Expected None, dict, or IDPConfig instance."
111+
)
105112

106113
self.config = config_model
107114
self.region = region or os.environ.get("AWS_REGION")

lib/idp_common_pkg/tests/unit/assessment/test_assessment_service.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
# Finally import application modules
2525
from idp_common.assessment.service import AssessmentService
26+
from idp_common.config.models import IDPConfig
2627
from idp_common.models import Document, Section, Status, Page
2728

2829

@@ -482,3 +483,45 @@ def test_process_document_section_empty_extraction_results(
482483
# Should return without error but log warning
483484
assert len(result.errors) == 0
484485
mock_get_json_content.assert_called_once()
486+
487+
def test_init_with_none_config(self):
488+
"""Test initialization with None config creates default IDPConfig."""
489+
service = AssessmentService(region="us-east-1", config=None)
490+
491+
assert service.region == "us-east-1"
492+
assert isinstance(service.config, IDPConfig)
493+
# Verify default config has assessment settings
494+
assert hasattr(service.config, "assessment")
495+
496+
def test_init_with_dict_config(self, mock_config):
497+
"""Test initialization with dict config converts to IDPConfig."""
498+
service = AssessmentService(region="us-east-1", config=mock_config)
499+
500+
assert service.region == "us-east-1"
501+
assert isinstance(service.config, IDPConfig)
502+
# Verify config was properly converted
503+
assert service.config.assessment.model == mock_config["assessment"]["model"]
504+
505+
def test_init_with_idpconfig_instance(self, mock_config):
506+
"""Test initialization with IDPConfig instance (the previously failing case)."""
507+
# Create an IDPConfig instance first
508+
config_instance = IDPConfig(**mock_config)
509+
510+
# Initialize service with IDPConfig instance
511+
service = AssessmentService(region="us-east-1", config=config_instance)
512+
513+
assert service.region == "us-east-1"
514+
assert isinstance(service.config, IDPConfig)
515+
# Should use the same instance
516+
assert service.config is config_instance
517+
# Verify config properties are accessible
518+
assert service.config.assessment.model == mock_config["assessment"]["model"]
519+
520+
def test_init_with_invalid_config_type(self):
521+
"""Test initialization with invalid config type raises ValueError."""
522+
# Try to initialize with an invalid config type (e.g., a string)
523+
with pytest.raises(ValueError) as exc_info:
524+
AssessmentService(region="us-east-1", config="invalid_config")
525+
526+
# Verify error message mentions the invalid type
527+
assert "Invalid config type" in str(exc_info.value)

0 commit comments

Comments
 (0)