Skip to content

Convert naive/local datetimes to UTC in TestResult and Step serialization#116

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/allow-local-time-input
Draft

Convert naive/local datetimes to UTC in TestResult and Step serialization#116
Copilot wants to merge 2 commits intomainfrom
copilot/allow-local-time-input

Conversation

Copy link

Copilot AI commented Feb 19, 2026

TestResult and Step reject naive datetimes at serialization time because hightime_datetime_to_protobuf requires UTC. Users providing datetime.now() get a cryptic ValueError: The tzinfo must be datetime.timezone.utc.

Changes

  • _grpc_conversion.py — Added _ensure_utc() helper that calls astimezone(timezone.utc), which correctly handles both naive datetimes (treated as local time) and tz-aware datetimes
  • _test_result.py, _step.py — Import and apply _ensure_utc() in to_protobuf() before passing datetimes to hightime_datetime_to_protobuf()

Example

# Previously raised: ValueError: The tzinfo must be datetime.timezone.utc.
test_result = TestResult(
    name="name",
    start_date_time=datetime.now(),   # naive local time — now accepted
    end_date_time=datetime.now(),
    outcome=Outcome.PASSED,
)
client.create_test_result(test_result)  # internally converts to UTC
Original prompt

This section details on the original issue you should resolve

<issue_title>Create result requires that I provide uct time</issue_title>
<issue_description>Trying to call create_test_result with the following code will throw an error that the start and end times have to be in utc. The python API should allow me to provide local time and internally convert to utc.

test_result = TestResult(
        name="name",
        start_date_time=datetime.now(),
        end_date_time=datetime.now(),
        outcome=Outcome.PASSED,
    )

AB#3746793</issue_description>

Comments on the Issue (you are @copilot in this section)


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

Adds _ensure_utc() helper to _grpc_conversion.py that converts naive
datetimes (treated as local time) to UTC before passing to
hightime_datetime_to_protobuf(). Uses it in to_protobuf() for both
TestResult and Step so that datetime.now() works without error.

Co-authored-by: csjall <4081815+csjall@users.noreply.github.com>
Copilot AI changed the title [WIP] Allow local time input for creating test results Convert naive/local datetimes to UTC in TestResult and Step serialization Feb 19, 2026
Copilot AI requested a review from csjall February 19, 2026 16:28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Ideally we should update the hightime_datetime_to_protobuf method in protobuf library to ensure UTC. This way each and every Python client which uses hightime_datetime_to_protobuf should not need to implement _ensure_utc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good long-term suggestion. However, ni-protobuf-types is a separate externally-published package (ni.protobuf.types v1.1.0) installed as a dependency — it lives in its own repository and would require its own release cycle to update. Since we can't change it from here, keeping _ensure_utc() in this library is the right approach. If the upstream fix is desired, it should be tracked as a separate issue/PR in the ni-protobuf-types repository.

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.

Create result requires that I provide uct time

2 participants

Comments