Defect #10098

last_login_on set to wrong time when config.active_record.default_timezone = :utc

Added by Nickolay Mischenko over 8 years ago. Updated 2 months ago.

Status:ConfirmedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Accounts / authenticationEstimated time:3.00 hours
Target version:-
Resolution: Affected version:1.3.0

Description

reproduce
  1. Set config.active_record.default_timezone = :utc in config/enviroment.rb
  2. Login with administrative user, go Administration -> Users
  3. Last connection time is wrong

example
for me, I've logged in as admin in "01/01/2012 06:41 pm", my server zone is UTC+11, last connection time = "02/01/2012 05:43 am", admin user zone is UTC
value must be "01/01/2012 07:41 am"

solution?
Time.zone.now should be used instead of Time.now when user logged-in or autologged-in

History

#1 Updated by Go MAEDA almost 4 years ago

  • Category changed from Time tracking to Accounts / authentication

#2 Updated by Go MAEDA 9 months ago

  • Status changed from New to Confirmed

Confirmed the issue.

the user logged on at 12:47:49 JST +0900, but User.first.last_login_on returns 12:47:49 UTC +00:00.

[6] pry(main)> User.first.last_login_on
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
=> Wed, 11 Dec 2019 12:47:49 UTC +00:00
[7] pry(main)> Time.zone.now
=> Wed, 11 Dec 2019 03:51:12 UTC +00:00

#3 Updated by Mizuki ISHIKAWA 2 months ago

It could not be reproduced in the development environment. May be due to differences in environment.
However, I agree with changing Time.now to Time.zone.now


PostgreSQL: Docker container (TZ=JST)
Redmine app: Docker container (TZ=JST)

Run the following command in the Redmine app container:

$ date
2020/7/14 Tuesday 11:14:36 JST

$ rails console
> User.first.last_login_on
Tue, 14 Jul 2020 02:01:28 UTC +00:00
> Time.zone.now
Tue, 14 Jul 2020 02:07:28 UTC +00:00

$ psql
# show timezone;
  TimeZone  
------------
 Asia/Tokyo
(1 row)

# select login, last_login_on from users;

 login |       last_login_on        
-------+----------------------------
       | 
       | 
       | 
 admin | 2020-07-14 02:01:28.928461
(4 rows)

Also available in: Atom PDF