Skip to content
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

Fix depracted utcfromtimestamp usage #4258

Open
wants to merge 1 commit into
base: current
Choose a base branch
from

Conversation

erkki
Copy link

@erkki erkki commented Dec 26, 2024

Deprecated as per https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp Fixes: TypeError: can't subtract offset-naive and offset-aware datetimes

Change Summary

Fix depracted utcfromtimestamp usage in dhcp.py.

Deprecated as per https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp

Fixes the following issue:

show dhcp server leases 
Traceback (most recent call last):
  File "/usr/libexec/vyos/op_mode/dhcp.py", line 545, in <module>
    res = vyos.opmode.run(sys.modules[__name__])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/opmode.py", line 312, in run
    res = func(**args)
          ^^^^^^^^^^^^
  File "/usr/libexec/vyos/op_mode/dhcp.py", line 335, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/libexec/vyos/op_mode/dhcp.py", line 387, in show_server_leases
    lease_data = _get_raw_server_leases(family=family, pool=pool, sorted=sorted, state=state, origin=origin)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/libexec/vyos/op_mode/dhcp.py", line 135, in _get_raw_server_leases
    data_lease['remaining'] = lease['expire_timestamp'] - datetime.now(timezone.utc)
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: can't subtract offset-naive and offset-aware datetimes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

dhcp

Proposed changes

How to test

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

Copy link

github-actions bot commented Dec 26, 2024


PR title does not match the required format

Deprecated as per https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp
Fixes: TypeError: can't subtract offset-naive and offset-aware datetimes
@erkki erkki force-pushed the fix-dhcp-deprecated-utcfromtimestamp branch from 79aee41 to bc08e72 Compare December 26, 2024 08:11
@erkki erkki changed the title Fix depracted utcfromtimestamp usage in dhcp.py dhcp: Fix depracted utcfromtimestamp usage Dec 26, 2024
Copy link

CI integration ❌ failed!

Details

CI logs

  • CLI Smoketests (no interfaces) ❌ failed
  • CLI Smoketests (interfaces only) ❌ failed
  • Config tests 👍 passed
  • RAID1 tests 👍 passed
  • TPM tests 👍 passed

Copy link
Member

@dmbaturin dmbaturin left a comment

Choose a reason for hiding this comment

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

Is there anything you plan to do before marking it ready for review? Seems sensible to me.

@erkki
Copy link
Author

erkki commented Jan 6, 2025

Is there anything you plan to do before marking it ready for review? Seems sensible to me.

Not really, just wanted to make sure it fits the contribution guidelines, passes tests etc. I will mark it as ready.

@erkki erkki changed the title dhcp: Fix depracted utcfromtimestamp usage Fix depracted utcfromtimestamp usage Jan 6, 2025
@erkki erkki marked this pull request as ready for review January 6, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants