cli icon indicating copy to clipboard operation
cli copied to clipboard

DeprecationWarning: datetime.datetime.utcnow() on version 1.3.48 (using python 3.12)

Open rui1610 opened this issue 1 year ago • 5 comments

Description

When running terraform_compliance 1.3.48 with python 3.12 I'm getting multiple DeprecationWarnings on the usage of datetime.datetime.utcnow().

Although terraform_compliance still works, this makes it difficult to read the output.

To Reproduce

Just run terraform_compliance with any feature file on python 3.12

Feature File:

Given I have ....
When it contains ...
Then it must ....
And it must ...

Plan File:

Sample Terraform Code:

resource "aws_s3_bucket" "example_code" {
   bucket = "This is just a sample code"
}

Used terraform-compliance Parameters:

Running via Docker:

Yes

Error Output:

. Converting terraform plan file.
🚩 Features     : /workspaces/tf_btp_info/tfscripts/tests/
🚩 Plan File    : /workspaces/tf_btp_info/tfscripts/mission_3774/step1/plan.out.json

🚩 Running tests. 🎉

/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:38: 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).
  feature.starttime = datetime.utcnow()
Feature: Certain variables should always be defined  # /workspaces/tf_btp_info/tfscripts/tests/naming_standards.feature
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:44: 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).
  scenario.starttime = datetime.utcnow()

    Scenario Outline: Naming Standard on all available variables
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:50: 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).
  step.starttime = datetime.utcnow()
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:68: 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).
  step.endtime = datetime.utcnow()
        Given I have not defined variable foo or moo
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:50: 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).
  step.starttime = datetime.utcnow()
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:68: 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).
  step.endtime = datetime.utcnow()
        Then scenario should fail
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:62: 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).
  scenario.endtime = datetime.utcnow()

    Examples:
        |  |
/usr/local/lib/python3.12/site-packages/radish/extensions/time_recorder.py:56: 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).
  feature.endtime = datetime.utcnow()

1 features (1 passed)
0 scenarios (0 passed)
0 steps (0 passed)

Expected Behavior:

Clean output without deprecation warnings.

Tested Versions:

  • terraform-compliance version: 1.3.48
  • terraform version: 1.9.1
  • python version: 3.12.4

Additional Context:

rui1610 avatar Jul 07 '24 08:07 rui1610

Same here.

terraform-compliance version: 1.3.48 terraform version: 1.9.3 python version: 3.12.4

WKeslerTH avatar Aug 10 '24 14:08 WKeslerTH

Hi, is there any update on this please ?

anthonydurot avatar Sep 25 '24 14:09 anthonydurot

Sorry for this guys, let me update it.

eerkunt avatar Oct 02 '24 14:10 eerkunt

Just released 1.3.49b1, have a try and let me know if you are still having problems, based on your response, I'll remove beta.

eerkunt avatar Oct 02 '24 16:10 eerkunt

I seem to still be seeing the same warnings on the beta (Python 3.12):

/Users/fakeUser/.local/pipx/venvs/terraform-compliance/lib/python3.12/site-packages/radish/extensions/time_recorder.py:56: 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).
  feature.endtime = datetime.utcnow()
$ terraform-compliance --version
terraform-compliance v1.3.49b1 initiated

1.3.49b1

chrisdaish avatar Oct 10 '24 09:10 chrisdaish

Deprecation output continues on version 1.3.48:

$ cat /etc/*release
Fedora release 40 (Forty)
NAME="Fedora Linux"
VERSION="40 (Workstation Edition)"
ID=fedora
VERSION_ID=40
VERSION_CODENAME=""
PLATFORM_ID="platform:f40"
PRETTY_NAME="Fedora Linux 40 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:40"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f40/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=40
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=40
SUPPORT_END=2025-05-13
VARIANT="Workstation Edition"
VARIANT_ID=workstation
Fedora release 40 (Forty)
Fedora release 40 (Forty)
$ which terraform-compliance
~/.local/bin/terraform-compliance
$ terraform-compliance --version
terraform-compliance v1.3.48 initiated

1.3.48

davidjeddy avatar Dec 09 '24 09:12 davidjeddy

If it helps anyone we have been able to suppress the errors by using/pinning Python 3.11 (based on the versions tested in the GitHub Actions pipelines) locally via pyenv and within our CICD by setting the Python version. This allows us to use new versions of terraform-compliance without the warnings.

chrisdaish avatar Mar 20 '25 16:03 chrisdaish

We are unable to pin due to compliance and security policies. When a new minor version of a language is published we are pushed to update as quickly as possible.

davidjeddy avatar Jul 03 '25 09:07 davidjeddy