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

NXDRIVE-2967: Upgrade the deprecated datetime adapter #5312

Conversation

gitofanindya
Copy link
Collaborator

@gitofanindya gitofanindya commented Oct 7, 2024

Summary by Sourcery

Upgrade the datetime handling to use timezone-aware datetime.now(tz=timezone.utc) instead of datetime.utcnow(). Update the Python version to 3.12 across all CI workflows and documentation.

Enhancements:

  • Replace usage of datetime.utcnow() with datetime.now(tz=timezone.utc) for better timezone handling.
  • Update locale retrieval logic to use locale.getlocale() instead of locale.getdefaultlocale().

CI:

  • Upgrade Python version from 3.9 to 3.12 in all GitHub Actions workflows for functional, unit, integration, lint, spell, style, translations, and types tests.

Documentation:

  • Update documentation to reflect support for Python 3.12.3 instead of Python 3.9.5.

Copy link
Contributor

sourcery-ai bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

This pull request upgrades the deprecated datetime adapter and updates the Python version from 3.9 to 3.12 across the project. The changes primarily focus on updating datetime usage to be timezone-aware and modifying the Python version in various configuration files and documentation.

Class diagram for updated datetime handling

classDiagram
    class BaseDAO {
        +execute(sql: str, parameters: Iterable[Any]) Cursor
    }
    class Engine {
        +increase_error(row: DocPair, error: str, details: str, incr: int)
        +unsynchronize_state(row: DocPair)
        +unset_unsychronised(row: DocPair)
        +synchronize_state(row: DocPair)
    }
    class RemoteWatcher {
        +scan_remote(from_state: DocPair)
    }

    BaseDAO --> Engine : uses
    Engine --> RemoteWatcher : uses

    note for BaseDAO "Updated execute method to handle timezone-aware datetime"
    note for Engine "Updated methods to use timezone-aware datetime"
    note for RemoteWatcher "Updated scan_remote to use timezone-aware datetime"
Loading

File-Level Changes

Change Details Files
Update datetime usage to be timezone-aware
  • Replace datetime.utcnow() with datetime.now(tz=timezone.utc)
  • Modify SQLite adapter to handle timezone-aware datetime objects
  • Update database operations to use timezone-aware datetime
nxdrive/dao/base.py
nxdrive/dao/engine.py
nxdrive/utils.py
nxdrive/engine/engine.py
nxdrive/engine/watcher/remote_watcher.py
Upgrade Python version from 3.9 to 3.12
  • Update Python version in GitHub Actions workflows
  • Modify deployment scripts to use Python 3.12.3
  • Update documentation to reflect new Python version
.github/workflows/functional_tests.yml
.github/workflows/functional_tests_2023.yml
.github/workflows/unit_tests.yml
.github/workflows/dead_code.yml
.github/workflows/integration_tests.yml
.github/workflows/lint.yml
.github/workflows/spell.yml
.github/workflows/style.yml
.github/workflows/translations.yml
.github/workflows/types.yml
docs/deployment.md
docs/gnu_linux.md
docs/support.md
tools/posix/deploy_ci_agent.sh
tools/windows/deploy_ci_agent.ps1
Update locale handling
  • Replace deprecated locale.getdefaultlocale() with locale.getlocale()
nxdrive/utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

sentry-io bot commented Oct 7, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: nxdrive/engine/engine.py

Function Unhandled Issue
_check_last_sync AttributeError: type object 'datetime.datetime' has no attribute 'datetime' nxdrive.engine...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @gitofanindya - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider refactoring the execute method in nxdrive/dao/base.py to improve readability. The added complexity for datetime handling could be extracted into a separate function.
  • Excellent job on consistently updating the Python version across all CI workflows and documentation. This thorough approach helps maintain consistency throughout the project.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -25,7 +25,24 @@ def execute(self, sql: str, parameters: Iterable[Any] = ()) -> Cursor:
while True:
count += 1
try:
return super().execute(sql, parameters)
if parameters:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider moving imports outside the execute method

Moving the imports (datetime and sqlite3) to the top of the file could improve performance, especially if this method is called frequently.

import datetime
import sqlite3

class BaseDAO:
    def execute(self, sql, parameters=None):
        count = 0
        while True:
            count += 1
            try:
                if parameters:

Comment on lines +48 to 50
As of now, we are using the __Python 3.12.3__.

History:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (documentation): Consider updating the History section if necessary.

If there's a history of Python versions used, it might be helpful to add this latest version to that list.

Suggested change
As of now, we are using the __Python 3.12.3__.
History:
As of now, we are using __Python 3.12.3__.
History:
- Python 3.12.3 (current)
- Python 3.9.5 (previous)

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 50.61%. Comparing base (74fc14e) to head (aa11d4e).
Report is 34 commits behind head on master.

Files with missing lines Patch % Lines
nxdrive/dao/base.py 93.33% 1 Missing ⚠️
nxdrive/engine/engine.py 50.00% 1 Missing ⚠️
nxdrive/engine/watcher/remote_watcher.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5312      +/-   ##
==========================================
+ Coverage   49.24%   50.61%   +1.37%     
==========================================
  Files          94       96       +2     
  Lines       15699    16123     +424     
==========================================
+ Hits         7731     8161     +430     
+ Misses       7968     7962       -6     
Flag Coverage Δ
functional 42.88% <83.33%> (+4.81%) ⬆️
integration 2.00% <0.00%> (-0.06%) ⬇️
unit 38.70% <87.50%> (+1.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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