Skip to content

fix(clickup): keep the instant an ISO due date names - #15157

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/clickup-due-date-timezone
Sep 20, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/clickup-due-date-timezone

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15155.

ClickUpClient.create_task converts an ISO due date like this:

dt_naive = datetime.fromisoformat(due_str.replace('Z', ''))
dt = tz.localize(dt_naive) if tz else dt_naive

tz is the user's pytz zone (production installs pytz==2023.3), and localize is only valid on a naive datetime. Two things go wrong:

A UTC due date has its Z stripped and is then localized as if the wall clock were the user's local time. 2026-09-21T17:00:00Z for an Asia/Kolkata user is stored as 11:30 UTC, five and a half hours before the instant that was asked for.

A due date that carries an explicit offset parses as aware, so localize raises ValueError: Not naive datetime (tzinfo is already set). The surrounding except Exception logs "Could not parse due date" and drops the key, so the task is created with no due date at all, the handler still answers ✅ Task created, and notify_task_created pushes the user a notification naming the due date they asked for.

The conversion now normalizes a trailing Z to +00:00, and only localizes when the parsed value is naive. An instant that already carries an offset is used as it is, which is what it means.

test_clickup_client.py gains three cases. Because the manifest lane has no pytz while production does, they install a small pytz stand-in whose localize refuses an aware datetime exactly as pytz does, so the tests exercise the production path rather than the degraded one: a Z due date keeps its instant, an offset due date reaches ClickUp instead of being dropped, and a naive one still resolves. The first two fail on main.

$ python3 plugins/omi-clickup-app/test_clickup_client.py
Ran 40 tests in 0.006s
OK

Failure-Class: none

Review in cubic

pytz.localize is only valid on a naive datetime. A trailing Z was stripped and the wall clock localized as the user's own time, moving a UTC due date by the user's offset, and an explicit offset made localize raise, so the surrounding except dropped the due date while the tool still reported success.
@singhharsh1708

Copy link
Copy Markdown
Contributor Author

Flagging the overlap before someone has to work it out: #14093 (for #13922) refactors this same block into a _coerce_due_date_ms helper. It is a different defect and it does not fix this one. Its helper keeps the two lines that cause it:

dt_naive = datetime.fromisoformat(token.replace('Z', ''))
dt = tz.localize(dt_naive) if tz else dt_naive

so a Z timestamp is still localized as the user's wall clock (5.5 hours early for Asia/Kolkata) and an offset-aware string still makes pytz.localize raise, which the caller swallows into a task with no due date.

If #14093 lands first I will rebase this onto its helper rather than reopening the old shape. If this lands first the helper can take the same parse.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Confirmed root cause: pytz localize() misused on tz-aware ISO due dates, causing wrong instants or silent due-date drops. Scoped fix + test, CI green. 5/5.

@kodjima33
kodjima33 merged commit c464afc into BasedHardware:main Sep 20, 2026
37 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.

[Bounty proposal] fix(clickup): a UTC due date is stored hours early and an offset one is silently dropped ($75 proposed)

2 participants