Aware datetime serialization changes scheduled-message instants by ignoring UTC offsets

Open
#980 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Kayvan-Zahiri is already working on this.

Since Oct 24, 2026.

  • #981 by @Kayvan-Zahiri — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Read the handwritten twilio.base.serialize.iso8601_datetime serializer and the public-client tests for scheduled messages. Reproduce the two timezone-offset cases through the mocked HTTP transport, then check that naive datetimes, date-only values, preformatted strings, and the unset sentinel retain their existing behavior. Done means aware datetimes serialize to the correct UTC instant; the issue reports that pull request #981 is already open.

Written by the indexing model from the issue text.

Description

Issue

The handwritten twilio.base.serialize.iso8601_datetime formats timezone-aware datetimes with strftime("%Y-%m-%dT%H:%M:%SZ") without converting their timezone to UTC. This changes the represented instant when the datetime has a nonzero UTC offset.

Through the public client (mocked HTTP transport), Client(...).messages.create(..., schedule_type="fixed", send_at=datetime(2030, 1, 2, 1, 30, tzinfo=timezone(timedelta(hours=5, minutes=30)))) currently sends SendAt=2030-01-02T01:30:00Z. It should send 2030-01-01T20:00:00Z. Negative offsets can similarly cross the next day. Twilio's scheduling timestamp documentation calls for a UTC ISO8601 timestamp.

Proposed fix and validation

Convert aware datetimes to UTC before adding the Z suffix. Keep naive datetimes, date-only values, preformatted strings and the unset sentinel's existing behavior. This touches the handwritten shared serializer, not generated REST methods.

Two public-client timezone cases fail before the fix; four controls pass. Afterward the full required make test workflow passes:647 tests, both Flake8 runs, Autoflake and Black (797 files). Tested Python3.12; no real messages or live Twilio requests, and no full Python matrix. AI-assisted contribution, maintainer review pending.

Dominant language
Python
Stars
2.1k
Forks
821
Avg merge
9h 33m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from twilio/twilio-python

All issues in twilio/twilio-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.