Skip to content

Replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) - #251

Open
msarg44 wants to merge 1 commit into
openshield-org:devfrom
msarg44:fix/deprecated-utcnow-sentinel-ingest
Open

Replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc)#251
msarg44 wants to merge 1 commit into
openshield-org:devfrom
msarg44:fix/deprecated-utcnow-sentinel-ingest

Conversation

@msarg44

@msarg44 msarg44 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Replaces three instances of datetime.datetime.utcnow() in sentinel/ingest.py with datetime.now(timezone.utc).

Why

datetime.utcnow() is deprecated since Python 3.12 and returns naive datetime objects, which can cause subtle timezone-related bugs in log ingestion pipelines where consistent UTC timestamps are important.

What changed

  • import datetimefrom datetime import datetime, timezone
  • Three datetime.datetime.utcnow() calls replaced with datetime.now(timezone.utc)
  • Removed manual + "Z" suffix on the isoformat line (now handled by timezone-aware datetime output)

This brings sentinel/ingest.py in line with the rest of the codebase — scanner/engine.py already uses datetime.now(timezone.utc) and imports from datetime with timezone.

…(timezone.utc)

datetime.utcnow() is deprecated since Python 3.12 and returns naive
datetimes. Replaced with datetime.now(timezone.utc) which returns
timezone-aware datetimes, consistent with the scanner/engine.py
convention used throughout the rest of the codebase.
@Vishnu2707

Copy link
Copy Markdown
Member

@msarg44 - Thanks for your contribution. CI seems to be failing, kindly recheck and provide the necessary fixes.

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.

2 participants