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

WIP: ♻️ adding UTC timezone to the project #3912

Conversation

matusdrobuliak66
Copy link
Contributor

@matusdrobuliak66 matusdrobuliak66 commented Feb 23, 2023

What do these changes do?

Adding timezone.utc to the whole repository. Now we will represent current time by the UTC time zone.
image

Related issue/s

How to test

Checklist

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Feb 23, 2023

Codecov Report

Merging #3912 (1da531d) into master (01a4445) will increase coverage by 1.3%.
The diff coverage is 92.8%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #3912     +/-   ##
========================================
+ Coverage    83.4%   84.8%   +1.3%     
========================================
  Files         933     847     -86     
  Lines       40063   37269   -2794     
  Branches      839     538    -301     
========================================
- Hits        33436   31611   -1825     
+ Misses       6406    5519    -887     
+ Partials      221     139     -82     
Flag Coverage Δ
integrationtests 61.6% <70.3%> (-0.1%) ⬇️
unittests 82.6% <92.8%> (+1.3%) ⬆️

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

Impacted Files Coverage Δ
...mcore_service_autoscaling/utils/dynamic_scaling.py 100.0% <ø> (ø)
...rc/simcore_service_api_server/api/routes/health.py 72.0% <50.0%> (ø)
.../server/src/simcore_service_webserver/login/cli.py 34.6% <50.0%> (ø)
...c/simcore_service_director_v2/api/routes/health.py 83.3% <66.6%> (-2.4%) ⬇️
.../simcore_service_api_server/models/schemas/jobs.py 94.7% <75.0%> (ø)
...rc/models_library/utils/pydantic_models_factory.py 93.6% <80.0%> (ø)
...ration/src/service_integration/commands/compose.py 75.5% <100.0%> (ø)
...src/simcore_service_api_server/api/routes/files.py 51.2% <100.0%> (ø)
...e_api_server/utils/solver_job_models_converters.py 87.8% <100.0%> (ø)
...imcore_service_autoscaling/dynamic_scaling_core.py 92.8% <100.0%> (+<0.1%) ⬆️
... and 124 more

@matusdrobuliak66 matusdrobuliak66 marked this pull request as ready for review February 23, 2023 16:22
Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

Ok I am not sure I understand this now.
I see you replaced utcnow() by now(timezone.utc).replace(tzinfo=None) correct?
but this does not make the time timezone aware or am I missing something?

# TODO: use dict for deep include/exclude! SEE https://pydantic-docs.helpmanual.io/usage/exporting_models/

if include is None:
include = set(f.name for f in model_fields)
include = {f.name for f in model_fields}
Copy link
Member

Choose a reason for hiding this comment

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

is this done automatically or you had to change manually?

@sanderegg
Copy link
Member

small test. Let's discuss that tomorrow:

import datetime
t = datetime.now()
t_aware = datetime.datetime.now(datetime.timezone.utc)
print(t)
print(t_aware)
print(t_aware.replace(tzinfo=None))
print(datetime.datetime.utcnow())

-->

2023-02-23 18:51:32.492593
2023-02-23 17:52:05.490572+00:00
2023-02-23 17:52:05.490572
2023-02-23 17:54:45.181448

@matusdrobuliak66
Copy link
Contributor Author

matusdrobuliak66 commented Feb 24, 2023

Ok I am not sure I understand this now. I see you replaced utcnow() by now(timezone.utc).replace(tzinfo=None) correct? but this does not make the time timezone aware or am I missing something?

@sanderegg I think this was requested by this comment: #3790 (comment)
It is recommended to stop using datetime.utcnow(). The problem with datetime.utcnow() and datetime.utcfromtimestamp() occurs because these return naive datetimes (i.e. with no timezone attached), and in Python 3, these are interpreted as system-local times. Explicitly specifying a time zone solves the problem. More reference https://blog.ganssle.io/articles/2019/11/utcnow.html

Update: I will make all the datetime "aware" of the timezone

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

You have 2 styles of replacement, which confuse me a bit:

  • .now(timezone.utc).replace(tzinfo=None)
  • .now(timezone.utc)

Why is it not the same everywhere?

NOTE: I have only comment on a few of them then I stopped.

@@ -23,7 +23,7 @@
status_code=status.HTTP_200_OK,
)
async def get_service_alive():
return f"{__name__}@{datetime.utcnow().isoformat()}"
return f"{__name__}@{datetime.now(timezone.utc).isoformat()}"
Copy link
Contributor

Choose a reason for hiding this comment

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

no replace timezone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Places, where the .repace(tzinfo=None) was added, were necessary because we later worked with the datetime that needed the format without tzinfo included inside. In the other cases (where .repace(tzinfo=None) was not included) it probably wasn't needed and it was ok to work with tzinfo included there (at least the unit tests were not complaining). But I can add it everywhere to be consistent if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also check the feedback from @sanderegg about this, I see that he also has some doubts.
In theory I would prefer to be working with UTC times all across the place, if possible. I'm not sure if this is doable though.

@matusdrobuliak66 matusdrobuliak66 marked this pull request as draft February 24, 2023 14:00
@matusdrobuliak66 matusdrobuliak66 changed the title ♻️ adding UTC timezone to the project WIP: ♻️ adding UTC timezone to the project Feb 24, 2023
@codeclimate
Copy link

codeclimate bot commented Feb 24, 2023

Code Climate has analyzed commit 1da531d and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Security 1

View more on Code Climate.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@matusdrobuliak66 matusdrobuliak66 self-assigned this Feb 27, 2023
Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

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

Is this draft (WIP) or should I review ? :-)

@matusdrobuliak66
Copy link
Contributor Author

Is this draft (WIP) or should I review ? :-)

Still work in progress. But I would welcome a consultation when you will have time.

@pcrespov pcrespov added this to the Jelly Beans milestone Apr 10, 2023
@pcrespov pcrespov modified the milestones: Jelly Beans, Pastel de Nata May 10, 2023
@pcrespov pcrespov modified the milestones: Pastel de Nata, Watermelon Jun 23, 2023
@pcrespov pcrespov modified the milestones: Watermelon, Sundae Jul 19, 2023
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.

Replace all utcnow with now(timezone.utc)
4 participants