Description
datetime.utcnow() has been deprecated since Python 3.12 and is removed in Python 3.14. The cookbook uses it in 104 places across 43 files. Some files already correctly use datetime.now(timezone.utc) — this should be made consistent.
Affected Areas
fundamentals/pycubrid/07_merge_upsert.py, 09_serial_order_numbers.py
templates/api-service-fastapi/recipes/ — 12+ files, heaviest offender
templates/flask/ — 15+ files
- Various other recipes
Impact
DeprecationWarning on Python 3.12+
AttributeError on Python 3.14 (method removed)
Files already correct (reference pattern)
fundamentals/pycubrid/11_bulk_etl_pipeline.py — uses datetime.now(timezone.utc)
fundamentals/pycubrid/14_manual_cascade_delete.py — uses datetime.now(timezone.utc)
Fix
Replace all occurrences:
# Before
datetime.utcnow()
# After (timezone-aware)
datetime.now(timezone.utc)
# After (naive UTC, if timezone-aware causes issues)
datetime.now(timezone.utc).replace(tzinfo=None)
Add from datetime import timezone to imports where missing.
Context
Found during line-by-line code review (2025-07-23).
Description
datetime.utcnow()has been deprecated since Python 3.12 and is removed in Python 3.14. The cookbook uses it in 104 places across 43 files. Some files already correctly usedatetime.now(timezone.utc)— this should be made consistent.Affected Areas
fundamentals/pycubrid/07_merge_upsert.py,09_serial_order_numbers.pytemplates/api-service-fastapi/recipes/— 12+ files, heaviest offendertemplates/flask/— 15+ filesImpact
DeprecationWarningon Python 3.12+AttributeErroron Python 3.14 (method removed)Files already correct (reference pattern)
fundamentals/pycubrid/11_bulk_etl_pipeline.py— usesdatetime.now(timezone.utc)fundamentals/pycubrid/14_manual_cascade_delete.py— usesdatetime.now(timezone.utc)Fix
Replace all occurrences:
Add
from datetime import timezoneto imports where missing.Context
Found during line-by-line code review (2025-07-23).