Skip to content

fix: cross-runtime consistency fixes#179

Open
sliedig wants to merge 5 commits intodevelopfrom
cross-runtime-fixes
Open

fix: cross-runtime consistency fixes#179
sliedig wants to merge 5 commits intodevelopfrom
cross-runtime-fixes

Conversation

@sliedig
Copy link
Contributor

@sliedig sliedig commented Mar 16, 2026

Issue number: #178

Summary

Changes

Fixes to align the Python runtime with Java, TypeScript, and .NET for functional equivalence and cross-runtime consistency.

Contracts Service (unicorn_contracts)

  • create_contract: replaced datetime.now().strftime("%d/%m/%Y %H:%M:%S") with datetime.now(timezone.utc).isoformat() for both contract_created and contract_last_modified_on
  • update_contract: changed UpdateExpression from "set contract_status=:t, modified_date=:m" to "set contract_status=:t, contract_last_modified_on=:m" — fixes a bug where updates wrote to a non-existent modified_date attribute
  • update_contract: updated timestamp to use datetime.now(timezone.utc).isoformat()
  • Added metrics.add_metric(name="ContractCreated", unit=MetricUnit.Count, value=1) to create_contract success path

Approvals Service (unicorn_approvals)

  • contract_status_changed_event_handler: moved now = datetime.now() and current_date computation inside the handler function body to capture per-invocation time rather than container initialisation time
  • Replaced raise InternalServerError(...) with raise EnvironmentError(...) for missing SERVICE_NAMESPACE and CONTRACT_STATUS_TABLE environment variables; removed unused InternalServerError import

Web Service (unicorn_web)

  • publication_evaluation_event_handler: added validation guard — only updates DynamoDB when evaluation_result is "APPROVED" or "DECLINED"; logs a warning and returns for any other value
  • Consolidated to a single PropertiesApproved metric — removed the duplicate PropertiesAdded metric

User experience

Before: Timestamps used a custom locale-specific format (DD/MM/YYYY HH:MM:SS) incompatible with other runtimes. The update_contract function silently wrote to a wrong DynamoDB attribute (modified_date). The approvals handler captured timestamps at container init time. The publication evaluation handler processed all evaluation result values without validation.

After: Timestamps use ISO 8601 format (YYYY-MM-DDTHH:MM:SS.ffffff+00:00) consistent with Java, TypeScript, and .NET. Contract updates correctly write to contract_last_modified_on. Each invocation captures its own timestamp. The publication evaluation handler only processes known result values, ignoring unexpected ones with a warning.

Checklist

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

sliedig added 4 commits March 16, 2026 09:31
…verError

- Remove unused datetime import and current_date variable calculation
- Replace InternalServerError with EnvironmentError for environment variable validation
- Simplify error handling for SERVICE_NAMESPACE and CONTRACT_STATUS_TABLE checks
- InternalServerError is not appropriate for environment configuration issues that occur at module initialization
…d remove unused metric

- Add validation for evaluation_result to ensure only "APPROVED" or "DECLINED" values are processed
- Return early with skip message when unknown evaluation result is encountered
- Log warning when evaluation result is invalid for debugging purposes
- Remove unused PropertiesAdded metric that was not being utilized
- Improve robustness by preventing invalid data from being written to DynamoDB
…trics

- Import timezone from datetime module for UTC timestamp generation
- Import MetricUnit from aws_lambda_powertools.metrics for proper metric typing
- Replace strftime formatting with isoformat() for ISO 8601 compliant timestamps in create_contract and update_contract functions
- Add metric tracking for successful contract creation events
- Rename UpdateExpression attribute from modified_date to contract_last_modified_on for consistency
- Ensures timestamps are timezone-aware and use UTC for consistency across distributed systems
@sliedig sliedig requested a review from a team as a code owner March 16, 2026 02:03
@github-actions github-actions bot requested a review from igorlg March 16, 2026 02:04
- Add actions: read permission for workflow execution access
- Add contents: read permission for repository content access
- Scope down GitHub Token permissions following security best practices
This was referenced Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants