Skip to content

[CLEANUP][SONAR][LOW]: Deprecated datetime.utcnow() usage in main.py #2377

@crivetimihai

Description

@crivetimihai

Severity: LOW
File: mcpgateway/main.py
Line: 5962
Rule: python:S6903

Description

The code uses datetime.utcnow() which is deprecated in Python 3.12. It creates a naive datetime without timezone info.

Code

# Line 5962
"timestamp": datetime.utcnow().isoformat(),

Impact

  • datetime.utcnow() returns a naive datetime (no timezone info)
  • Deprecated in Python 3.12, will be removed in future versions
  • Can cause timezone-related bugs when comparing with aware datetimes

Suggested Fix

Use timezone-aware datetime:

from datetime import datetime, timezone

"timestamp": datetime.now(timezone.utc).isoformat(),

Metadata

Metadata

Assignees

Labels

COULDP3: Nice-to-have features with minimal impact if left out; included if time permitschoreLinting, formatting, dependency hygiene, or project maintenance choresgood first issueGood for newcomerspythonPython / backend development (FastAPI)sonarSonarQube code quality findings

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions