Skip to content

refactor(health): replace deprecated datetime.utcnow() with timezone-aware datetime#1056

Open
MrButtCode wants to merge 1 commit intoCCExtractor:masterfrom
MrButtCode:fix/datetime-deprecation
Open

refactor(health): replace deprecated datetime.utcnow() with timezone-aware datetime#1056
MrButtCode wants to merge 1 commit intoCCExtractor:masterfrom
MrButtCode:fix/datetime-deprecation

Conversation

@MrButtCode
Copy link

Resolves multiple DeprecationWarnings in mod_health/controllers.py caused by the use of datetime.utcnow().

Python 3.12 formally deprecated datetime.utcnow() in favor of timezone-aware objects. To harden the health module for newer Python runtimes while preserving the exact JSON API contract for existing consumers, I migrated the calls to datetime.now(timezone.utc).

To prevent Python from appending the explicit +00:00 timezone offset (which would break the existing .isoformat() + 'Z' manual concatenation), the timezone info is stripped prior to formatting using .replace(tzinfo=None). This ensures flawless backward compatibility with the current frontend/API consumers while satisfying Python 3.12+ requirements.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2026

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.

1 participant