-
Notifications
You must be signed in to change notification settings - Fork 449
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
refactor: datetime.now() to datetime.utcnow() #556
refactor: datetime.now() to datetime.utcnow() #556
Conversation
@isabelcosta, in this PR I only replace the occurrences of datetime.now(). I didn't change the time.time() in register user and its related cron job and test. Let me know if you want this to be change as well. |
app/api/dao/user.py
Outdated
return ( | ||
messages.USER_USES_A_USERNAME_THAT_ALREADY_EXISTS, | ||
HTTPStatus.BAD_REQUEST, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.... apart from adding utcnow() , i can see that you have done the formatting of most of the returning messages with the response then I think you can change the title of the issue or this PR to something relevant to it or you can also elaborate about this in the description of this PR as well so, that it can easily help anyone to understand exactly what all you have done in this PR ... [just a suggestion,] BTW, its a greatly needed change in the PR 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oopss.. I think this must be the autopep or something I accidentally set to 'ON' in my VSCode IDE. I'll fix it and push again.. Nice catch, @robotjellyzone. Thanks again. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm. I think it's the Prettier on VSCode doing this auto-prettying stuff. hehehe.. should I just add a little explanation on the PR that I did a little formatting a bit, rather than changing it back to how it was. Will it make any different if I reverse it back? I think the difference is only from one line to two lines. @robotjellyzone, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should mention this in your description of this PR but I think then you have to go through the various other files as well to make sure this consistency should be maintained with other response messages as well so, maybe let's just wait for @isabelcosta to suggest !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I think before I change anything, I'll wait for @isabelcosta to give her thoughts then. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the culprit. I set both Python > Linting: Lint On Save and Python > Linting: Pylint Enabled to True. Mmm... I actually quite like these options to be on, just to make sure the codes abide the Linting standards. I'll probably mention this is PR as additional note and if need to, for the rest of the files we can schedule some code reformatting period (once a month or every 2-3 month?) just to make sure code quality is kept in check. It'll be similar to what I did with PR#478 last time, but in smaller scale as opposed to the whole project (probably folder by folder). Anyway, we'll wait for @isabelcosta, or perhaps @ramitsawhney27 can also give us advise on this 😆 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code reformatting period (once a month or every 2-3 month?)
This is interesting definitely! However, the real solution I think would be, doing a refactor on the style, and ensure that from a point in time, contributors are required to run a linting tool that does such code formatting. Just like we started talking for black
tool. I am just not sure about which tool to use 🤔
Thanks, @ramitsawhney27 for giving your approval. On the discussion I have with @robotjellyzone, can you pls share your thoughts on this? I really appreciate your support 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand there was some reformating in the PR which is good but at the same time some are not related to this issue. I feel I can overlook this and start a conversation on what tool to use to have this issue solved, and have everyone using the same, in this way minimizing these reformats.
Other than that the code seems nice :) Thank you so much for this contribution @mtreacy002 🎉
app/api/dao/user.py
Outdated
return ( | ||
messages.USER_USES_A_USERNAME_THAT_ALREADY_EXISTS, | ||
HTTPStatus.BAD_REQUEST, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code reformatting period (once a month or every 2-3 month?)
This is interesting definitely! However, the real solution I think would be, doing a refactor on the style, and ensure that from a point in time, contributors are required to run a linting tool that does such code formatting. Just like we started talking for black
tool. I am just not sure about which tool to use 🤔
@robotjellyzone if you were to ignore the formatting, would you approve this PR? |
Yeah sure @isabelcosta ! Everything is totally fine & perfect. You did a great job @mtreacy002 👍 , I just thought that it would be great if @mtreacy002 just elaborate about these formatting in the description as well [this will improve PR review for every new reviewer] as its always good to know what all this PR is doing . [even if its doing a small change, as no change is small at all in open source :)] |
@robotjellyzone you are totally right :) 👏 PR description needs to be clear about changes done here, @mtreacy002 can you please update it to reflect that? |
@isabelcosta and @robotjellyzone, I had changed the PR description to include the reformatting, is this ok? If you think I need to elaborate further, can you please explain into how much details you want this elaboration should be (can you give me example, please)? Thanks beforehand |
I think its fine now @mtreacy002 👍 what do you think @isabelcosta ? also, i think that a separate issue needs to be created to ensure consistency in the entire code or can you do the formatting of the entire code in this PR itself @mtreacy002 [as you are already describing this] or should create a new issue for that? |
I can do the reformatting of whole project again using black tools like last time, @robotjellyzone. @isabelcosta, what do you think of this? Let me know if you want me to do it in this PR or open a separate issue for it. 😉 |
In my opinion, it's good that you've improved the format structure, generally good to have linters like autopep on. As for formatting the entire project, I think that's a different task, for which feel free to open the issue. I think we can do without having it in this PR, and we can also do without changing the existing PR's format. |
Thanks, @ramitsawhney27 for sharing your thoughts 😃. @isabelcosta, we probably can bring this up to our coding team meeting to discuss about having a routine schedule for code refactoring. |
Yeah, thanks @ramitsawhney27 👍 so, a new issue would be a lot better idea. Now, I think this PR is ready to merge but before that testing needs to be done [as label said] @isabelcosta @mtreacy002 . great job 🎉 !! |
The test here that comes to my mind, is simply creating a user, calling some endpoints and see if the time is correct?! 🤷♀️ @anitab-org/qa-team |
I am also thinking about its testing part as I am not sure how should I ensure that it's storing it in UTC maybe I should try to print those values in my terminal/console as since it will be storing time in our zone ie UTC so, we can try to print it to ensure this [not sure though] !! let me check this 🤔 💭 |
@mtreacy002 @isabelcosta any endpoints apart from GET user (screenshot below) that can be tested for this PR? |
Hi @rpattath i think you need to test this for mentorship relation and task creation as the changes have been done in those places only [for making utc time in mentorship relation ] |
@mtreacy002 I am seeing this for request creation datetime. I created the request just a few minutes before the time on the left hand side of the screenshot. On the right hand side of the screenshot you see the output of the request creation_date timestamp from the swagger UI. That does not look correct to me. |
@rpattath , can you tell me how you get the time on the left?
|
@mtreacy002 I am using https://www.unixtimestamp.com/index.php to convert float timestamp to datetime format. That website by default prints the current timestamp on the left.
4:42pm my time is 8:42pm UTC
|
So, as far as this PR concern, we did get the time recorded in UTC. The thing is the Float data type creates discrepancy from the data recorded to the data retrieved. I think we should open another issue for this so we can deal with it separately. What do you think @isabelcosta, @ramitsawhney27, @robotjellyzone and @rpattath? |
The floating value cannot cause discrepancy, I am not sure if that is the case. @rpattath Apologies, but if you have some bandwidth, can you re-test this again just to be sure? There shouldn't be such a large discrepancy if you say you launched the request some minutes ago. |
@SanketDG @mtreacy002 I am still seeing the same. I created the request at 05/18/2020 @ 10:42pm (UTC) |
@mtreacy002 do you have any suggestions on how to test the recorded datetime with this existing issue? At this point I am not sure how to test this PR. |
Hi @Roshni, @robotjellyzone.
HOWEVER, the next step needs to be taken so that when a user retrieve the data (which is recorded in UTC+0), they must see it in their own timezone (converted). Because this action (retrieving data) can be done by anyone, can be the user related to the data or other users who can be located anywhere with different Timezone (UTC offset). So, like in the example test above, I'm in UTC+10, when I retrieve the data, I need to see it in my own timezone (May 20th 07:39PM AEST). And If an admin located in Los Angeles retrieve the user data I just created, they need to see it as May 20th 02:39AM PDT. But in the database, we must record it on its natural UTC+0 format (May 20th 09:39AM). Hope this makes sense. @isabelcosta and @ramitsawhney27, should we open few issues to deal with this on Mentorship System repos?
In my BridgeInTech DB design, I've taken this into consideration by having timezone column on users_extension table. |
I'm gonna give one function of the mentorship relation (e.g. send request) a test now. will update you all soon. |
So, here's the test I did on Mentorship Relation send request. Steps:
What went wrong here? Upon further investigation I found out that we have an extra step in the code to record where as in the email verification date for user register (app/api/dao/user.py line 349), we've only using datetime.utcnow() without Now, this is a good pick up, @rpattath. This means we have to check all codes dealing with date if they're using Can you please open an issue for this bug ( |
Ok, so I ran the send request from develop branch (with This is explained in the python docs that .timestamp() returns posix timestamp with float value similar to what is returned by time.time() we used in register method to record @isabelcosta and @ramitsawhney27. I think we need to decide which of the three methods to record date in UTC+0 we're going to use throughout the project (for consistency):
I haven't look closely to every single code where they are being used to see if using only one option out of the three will be a possible solution. |
Opened this issue and moving this PR to Needs Review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtreacy002 please solve the merge conflicts
@mtreacy002 hey can you please resolve the conflicts , as this PR already has 2 approving reviews after conflicts are solved it can be directly tested:) |
refactor test datetime.now() on happy_path
c1c8a9f
cba588c
to
c1c8a9f
Compare
Codecov Report
@@ Coverage Diff @@
## develop #556 +/- ##
========================================
Coverage 92.50% 92.50%
========================================
Files 38 38
Lines 2014 2014
========================================
Hits 1863 1863
Misses 151 151
|
Done, @vj-codes 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Tested locally and working fine. All instances of datetime.now()
are replaced by datetime.utcnow()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 😄
Thank you for updating this PR @mtreacy002 🙌🏾
Description
This PR is to replace all occurrences of datetime.now() too datetime.utcnow()
Fixes #555
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
I tested this by running python run.py and register/login which worked as normal. I also tested this by running unittests resulted in all tests passed.
Checklist:
Code/Quality Assurance Only
Additional Notes
Some part of the codes were reformatted through this PR using VSCode auto-enabled pylint.