Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

@emmanuel-ferdman emmanuel-ferdman commented May 1, 2025

PR Summary

This PR fixes the DeprecationWarning that appears in Python 3.12+ when using datetime.utcnow(). It replaces it with a more future-proof approach: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None). This keeps the datetime object naive (without timezone info), which is important for parts of the code that expect it that way, but avoids the warning by using a timezone-aware method first:

# Before (deprecated)  
from datetime import datetime  
naive_time = datetime.utcnow()  # Raises warning  

# Common Fix (timezone-aware)  
from datetime import datetime, timezone  
aware_time = datetime.datetime.now(datetime.timezone.utc)  # Breaks naive-dependent code  

# This PR's Fix (naive but compliant)  
from datetime import datetime, timezone  
compliant_time = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)  # No warning, backward-compatible  

You can see those warnings in the latest CI run:

  D:\a\boofuzz\boofuzz\boofuzz\fuzz_logger_csv.py:24: 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).
    s = datetime.datetime.utcnow().isoformat()

unit_tests/test_session_failure_handling.py::TestNoResponseFailure::test_no_response_causes_restart
  D:\a\boofuzz\boofuzz\boofuzz\sessions\session.py:174: 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).
    self._run_id = datetime.datetime.utcnow().replace(microsecond=0).isoformat().replace(":", "-")

@SR4ven
Copy link
Collaborator

SR4ven commented May 3, 2025

Thank you for the contribution @emmanuel-ferdman!

@SR4ven SR4ven merged commit 36e1e73 into jtpereyda:master May 3, 2025
13 checks passed
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