Skip to content

cassandra/query: use timezone specific API to avoid deprecated warning #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

tchaikov
Copy link

before this change, when testing with cqlsh using some dtest based tests, we have failures like:

------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------
15:10:02,963 ccm             DEBUG cluster.py     :754  | node1: (EE) /home/kefu/dev/scylladb/tools/cqlsh/bin/cqlsh.py:1063: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future vers
ion. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
15:10:02,963 cqlsh_tests.cqlsh_tests ERROR cqlsh_tests.py :534  | /home/kefu/dev/scylladb/tools/cqlsh/bin/cqlsh.py:1063: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version.
 Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
----------------------------------------------------------------------------------------------- Captured log teardown ------------------------------------------------------------------------------------------------                        15:10:05,989 dtest_setup     DEBUG dtest_setup.py :629  | exclude_errors: []
15:10:05,993 dtest_setup     DEBUG dtest_setup.py :718  | removing ccm cluster test at: /home/kefu/.dtest/dtest-kguqevx3
15:10:06,002 dtest_setup     DEBUG dtest_setup.py :721  | clearing ssl stores from [/home/kefu/.dtest/dtest-kguqevx3] directory
15:10:06,002 dtest_setup     DEBUG dtest_setup.py :85   | Freeing cluster ID 20: link /home/kefu/.dtest/20
================================================================================================== warnings summary ==================================================================================================                        <frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtim
estamp(timestamp, datetime.UTC).

cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=true]
cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=false]
  /home/kefu/.local/lib/python3.12/site-packages/pytest_elk_reporter.py:281: 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).
    timestamp=datetime.datetime.utcnow().isoformat(),

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================== short test summary info ===============================================================================================
FAILED cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=true] - AssertionError: Failed to execute cqlsh
FAILED cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=false]
- AssertionError: Failed to execute cqlsh

this happens because the warnings are printed to stderr, and we take non-empty output in stderr as an indication of test failure.

in this change, we replace the deprecated API with timezone-aware API, to avoid this warning.

and the tests passed.

before this change, when testing with cqlsh using some dtest based
tests, we have failures like:

```
------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------
15:10:02,963 ccm             DEBUG cluster.py     :754  | node1: (EE) /home/kefu/dev/scylladb/tools/cqlsh/bin/cqlsh.py:1063: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future vers
ion. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
15:10:02,963 cqlsh_tests.cqlsh_tests ERROR cqlsh_tests.py :534  | /home/kefu/dev/scylladb/tools/cqlsh/bin/cqlsh.py:1063: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version.
 Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
----------------------------------------------------------------------------------------------- Captured log teardown ------------------------------------------------------------------------------------------------                        15:10:05,989 dtest_setup     DEBUG dtest_setup.py :629  | exclude_errors: []
15:10:05,993 dtest_setup     DEBUG dtest_setup.py :718  | removing ccm cluster test at: /home/kefu/.dtest/dtest-kguqevx3
15:10:06,002 dtest_setup     DEBUG dtest_setup.py :721  | clearing ssl stores from [/home/kefu/.dtest/dtest-kguqevx3] directory
15:10:06,002 dtest_setup     DEBUG dtest_setup.py :85   | Freeing cluster ID 20: link /home/kefu/.dtest/20
================================================================================================== warnings summary ==================================================================================================                        <frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtim
estamp(timestamp, datetime.UTC).

cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=true]
cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=false]
  /home/kefu/.local/lib/python3.12/site-packages/pytest_elk_reporter.py:281: 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).
    timestamp=datetime.datetime.utcnow().isoformat(),

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================== short test summary info ===============================================================================================
FAILED cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=true] - AssertionError: Failed to execute cqlsh
FAILED cqlsh_tests/cqlsh_tests.py::TestCqlshWithSSL::test_tracing[require_client_auth=false]
- AssertionError: Failed to execute cqlsh
````

this happens because the warnings are printed to stderr, and we take
non-empty output in stderr as an indication of test failure.

in this change, we replace the deprecated API with timezone-aware API,
to avoid this warning.

and the tests passed.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
Copy link

@fruch fruch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Could you also send this PR to upstream, to decrease conflicts amount in the future?

@tchaikov
Copy link
Author

Makes sense. Could you also send this PR to upstream, to decrease conflicts amount in the future?

sure thing. Will do the next morning.

@Lorak-mmk Lorak-mmk merged commit fee957a into scylladb:master Jun 23, 2024
19 checks passed
@fruch
Copy link

fruch commented Jun 23, 2024

@Lorak-mmk

We should look into failing the unittes on warnings

That would help us catching/attending to those sooner

@tchaikov tchaikov deleted the tz-timedelta branch June 23, 2024 14:19
@tchaikov
Copy link
Author

Makes sense. Could you also send this PR to upstream, to decrease conflicts amount in the future?

sure thing. Will do the next morning.

datastax#1213

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.

3 participants