You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tooling.apache.org by "andrewmusselman (via GitHub)" <gi...@apache.org> on 2026/05/22 18:34:45 UTC
[I] ISSUE-012 - `datetime.utcnow()` deprecation warnings across 23 call sites (tooling-gofannon)
andrewmusselman opened a new issue, #30:
URL: https://github.com/apache/tooling-gofannon/issues/30
### Summary
Python 3.12 deprecated `datetime.utcnow()` because it returns a naive datetime that *claims* to be UTC but has no tzinfo attached — a longstanding footgun. The codebase has 23 call sites across 8 files emitting deprecation warnings on every code path that touches them.
### Details
**Symptom:**
```
/app/services/data_store_service.py:473: DeprecationWarning: datetime.datetime.utcnow()
is deprecated and scheduled for removal in a future version. Use timezone-aware
objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
```
**Scope (file-by-file count):**
- `session_service.py` — 4 uses (includes a comparison at line 126)
- `data_store_service.py` — 4 uses
- `chat_service.py` — 4 uses
- `observability_service.py` — 2 uses
- `routes.py` — 3 uses
- `dependencies.py` — 3 uses
- `access_tracking.py` — 1 use
- `user_service.py` — 2 uses
- **Total: 23 uses**
The comparison in `session_service.py:126` (`session.expires_at <= datetime.utcnow()`) is why this needs to be fixed in one sweep rather than file-by-file: mixing naive and aware datetimes raises `TypeError` at comparison time.
**Impact:**
Cosmetic noise in logs today; will become a hard breakage in a future Python release. Mixing strategies across the codebase risks runtime TypeError on datetime comparisons.
### Remediation
**Strategy A (recommended): drop-in equivalent, keeps wire format identical.**
```python
# Old:
datetime.utcnow()
# New:
datetime.now(timezone.utc).replace(tzinfo=None)
```
Still naive, isoformat output unchanged (`2024-05-15T12:34:56.789`, no offset). Existing CouchDB data unchanged. Strategy B (full timezone-aware) is a separate, planned change with a data migration.
**One-shot replacement:**
```bash
cd webapp/packages/api/user-service
grep -rl "datetime\.utcnow()" --include="*.py" . | xargs sed -i \
's/datetime\.utcnow()/datetime.now(timezone.utc).replace(tzinfo=None)/g'
grep -rln "from datetime import" --include="*.py" . | while read f; do
if ! grep -q "from datetime import.*timezone" "$f"; then
sed -i -E 's/^from datetime import datetime(, .+)?$/from datetime import datetime, timezone\1/' "$f"
fi
done
```
### Acceptance Criteria
- [ ] Fixed: All 23 `datetime.utcnow()` calls replaced
- [ ] Fixed: `timezone` imported wherever `datetime` is imported
- [ ] Test added: `grep datetime.utcnow webapp/...` returns nothing
- [ ] Verified: No `DeprecationWarning: utcnow()` in api logs after restart
- [ ] Verified: Existing CouchDB documents readable (no format drift)
### References
- File: All 8 files listed above under `webapp/packages/api/user-service/`
- Tracker: FIXES.md item #9
### Priority
**Low** - Cosmetic noise reduction; not blocking. Mechanical fix takes <30 minutes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org
Re: [I] ISSUE-012 - `datetime.utcnow()` deprecation warnings across 23 call sites (tooling-gofannon)
Posted by "andrewmusselman (via GitHub)" <gi...@apache.org>.
andrewmusselman closed issue #30: ISSUE-012 - `datetime.utcnow()` deprecation warnings across 23 call sites
URL: https://github.com/apache/tooling-gofannon/issues/30
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org