Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

DeprecationWarning warning in build log for python 3.12 datetime.datetime.utcnow() is deprecated #1194

@parthea

Description

@parthea

See warning below which appears in the Kokoro build log

tests/unit/test_client.py: 3 warnings
  /tmpfs/src/github/python-storage/google/cloud/storage/_signing.py:144: 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).
    now = NOW().replace(tzinfo=_helpers.UTC)

Remove usage here:

NOW = datetime.datetime.utcnow # To be replaced by tests.

Also usage in tests here:
https://github.com/search?q=repo%3Agoogleapis%2Fpython-storage%20datetime.datetime.utcnow&type=code


tests/unit/test__signing.py: 27 warnings
tests/unit/test_client.py: 3 warnings
  /tmpfs/src/github/python-storage/google/cloud/storage/_signing.py:144: 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).
    now = NOW().replace(tzinfo=_helpers.UTC)

tests/unit/test__signing.py::Test_generate_signed_url_v4::test_with_access_token_and_service_account_email
tests/unit/test__signing.py::Test_generate_signed_url_v4::test_with_access_token_and_service_account_email_and_signer_email
tests/unit/test__signing.py::Test_generate_signed_url_v4::test_with_service_account_email_and_signer_email
tests/unit/test__signing.py::Test_generate_signed_url_v4::test_with_signer_email
tests/unit/test__signing.py::Test_generate_signed_url_v4::test_with_token_and_signer_email
  /tmpfs/src/github/python-storage/google/cloud/storage/_signing.py:641: 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).
    now = NOW()

tests/unit/test_blob.py::Test_Blob::test__set_properties_w_kms_key_name
tests/unit/test_blob.py::Test_Blob::test__set_properties_wo_kms_key_name
  /tmpfs/src/github/python-storage/tests/unit/test_blob.py:139: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_blob.py: 36 warnings
  /tmpfs/src/github/python-storage/tests/unit/test_blob.py:472: 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).
    expiration = datetime.datetime.utcnow().replace(tzinfo=UTC) + delta

tests/unit/test_blob.py::Test_Blob::test_generate_signed_url_v2_w_expiration
  /tmpfs/src/github/python-storage/tests/unit/test_blob.py:570: 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).
    expiration = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_IAMConfiguration::test_ctor_explicit_bpo
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:476: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_IAMConfiguration::test_ctor_explicit_ubla
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:436: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_IAMConfiguration::test_ctor_ubla_and_bpo_time
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:506: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_IAMConfiguration::test_from_api_repr_w_enabled
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:556: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_Bucket::test_autoclass_toggle_and_tsc_update_time
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:2685: 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).
    effective_time = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py: 26 warnings
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:4056: 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).
    expiration = datetime.datetime.utcnow().replace(tzinfo=UTC) + delta

tests/unit/test_bucket.py::Test_Bucket::test_generate_signed_url_v2_w_expiration
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:4162: 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).
    expiration = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_Bucket::test_iam_configuration_policy_w_entry
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:2332: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_bucket.py::Test_Bucket::test_retention_policy_effective_time
  /tmpfs/src/github/python-storage/tests/unit/test_bucket.py:2812: 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).
    effective_time = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_client.py::TestClient::test_create_hmac_key_defaults
tests/unit/test_client.py::TestClient::test_create_hmac_key_explicit_project
tests/unit/test_client.py::TestClient::test_create_hmac_key_w_retry
tests/unit/test_client.py::TestClient::test_create_hmac_key_w_timeout
tests/unit/test_client.py::TestClient::test_create_hmac_key_w_user_project
  /tmpfs/src/github/python-storage/tests/unit/test_client.py:2259: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_client.py::TestClient::test_get_hmac_key_metadata_w_project
tests/unit/test_client.py::TestClient::test_get_hmac_key_metadata_wo_project
tests/unit/test_client.py::TestClient::test_get_service_account_email_w_project
tests/unit/test_client.py::TestClient::test_get_service_account_email_wo_project
  /tmpfs/src/github/python-storage/.nox/unit-3-12/lib/python3.12/site-packages/google/api_core/datetime_helpers.py:45: 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).
    return datetime.datetime.utcnow()

tests/unit/test_client.py::TestClient::test_get_signed_policy_v4_bucket_bound_hostname
tests/unit/test_client.py::TestClient::test_get_signed_policy_v4_bucket_bound_hostname_with_scheme
tests/unit/test_client.py::TestClient::test_get_signed_policy_v4_virtual_hosted_style
  /tmpfs/src/github/python-storage/google/cloud/storage/client.py:1621: 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).
    now = _NOW()

tests/unit/test_hmac_key.py::TestHMACKeyMetadata::test_time_created_getter
  /tmpfs/src/github/python-storage/tests/unit/test_hmac_key.py:180: 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).
    now = datetime.datetime.utcnow()

tests/unit/test_hmac_key.py::TestHMACKeyMetadata::test_updated_getter
  /tmpfs/src/github/python-storage/tests/unit/test_hmac_key.py:190: 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).
    now = datetime.datetime.utcnow()

tests/unit/test_transfer_manager.py::test_upload_chunks_concurrently_with_metadata_and_encryption
  /tmpfs/src/github/python-storage/tests/unit/test_transfer_manager.py:847: 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).
    now = datetime.datetime.utcnow().replace(tzinfo=UTC)

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.type: cleanupAn internal cleanup or hygiene concern.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions