Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 20, 2025

Resolves PostgreSQL DateTime compatibility issues when calling GetPendingActivity() that resulted in the error:

Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported

Problem

PostgreSQL's timestamp with time zone columns require DateTime values with Kind=Utc, but the ActivityController was passing DateTime values with incompatible kinds:

  1. _dateTimeProvider.Now (Kind=Local) to GetFirstOpenSubscription
  2. DateTime.MaxValue (Kind=Unspecified) for token expiry in SetSubscriptionToken

This caused runtime exceptions when using the PostgreSQL persistence provider with activities.

Solution

Made minimal changes to ActivityController.cs to ensure PostgreSQL compatibility:

// Line 37: Use UTC time for subscription queries
- subscription = await _subscriptionRepository.GetFirstOpenSubscription(Event.EventTypeActivity, activityName, _dateTimeProvider.Now);
+ subscription = await _subscriptionRepository.GetFirstOpenSubscription(Event.EventTypeActivity, activityName, _dateTimeProvider.UtcNow);

// Line 54: Use UTC DateTime.MaxValue for token expiry
- TokenExpiry = DateTime.MaxValue
+ TokenExpiry = new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc)

Impact

  • ✅ Fixes PostgreSQL "Cannot write DateTime with Kind=Local" runtime error
  • ✅ Preserves exact same date/time values, only corrects DateTimeKind
  • ✅ Maintains backward compatibility with all persistence providers (memory, SQL Server, MongoDB, etc.)
  • ✅ Aligns with existing patterns used elsewhere in the codebase (e.g., UserStepContainer uses DateTime.Now.ToUniversalTime())

The changes are minimal and surgical, affecting only the specific DateTime handling that caused PostgreSQL compatibility issues while maintaining full functionality across all supported persistence providers.

Fixes #1329.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Postgres sql Datetime convention issue Fix PostgreSQL DateTime compatibility issue in ActivityController Sep 20, 2025
Copilot AI requested a review from danielgerlag September 20, 2025 00:44
@danielgerlag danielgerlag marked this pull request as ready for review September 20, 2025 16:19
@danielgerlag danielgerlag merged commit 1519f4f into master Sep 20, 2025
9 of 10 checks passed
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.

Postgres sql Datetime convention issue

2 participants