Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Why not datetime.utcnow() in auto_now/auto_now_add
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jedie  
View profile  
 More options Nov 24 2009, 11:10 am
From: jedie <google.gro...@jensdiemer.de>
Date: Tue, 24 Nov 2009 08:10:52 -0800 (PST)
Local: Tues, Nov 24 2009 11:10 am
Subject: Why not datetime.utcnow() in auto_now/auto_now_add
DateTimeField "auto_now" and "auto_now_add" used datetime.now(). But
why this? IMHO it's better to use datetime.utcnow(), isn't it?

Mfg.

Jens Diemer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Nov 24 2009, 6:36 pm
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Wed, 25 Nov 2009 07:36:41 +0800
Local: Tues, Nov 24 2009 6:36 pm
Subject: Re: Why not datetime.utcnow() in auto_now/auto_now_add

On Wed, Nov 25, 2009 at 12:10 AM, jedie <google.gro...@jensdiemer.de> wrote:
> DateTimeField "auto_now" and "auto_now_add" used datetime.now(). But
> why this? IMHO it's better to use datetime.utcnow(), isn't it?

Why would it be? A datetime field isn't necessarily stored in UTC. It
uses datetime.now() because that will return the same time as
settings.TIME_ZONE.

On top of that, making this change would be a *huge* backwards
incompatibility, as any existing uses of auto_now etc would break.

Time zone handling is definitely something that Django could handle
better, but simply switching to UTC for certain functions isn't the
solution.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jedie  
View profile  
 More options Nov 25 2009, 6:10 am
From: jedie <google.gro...@jensdiemer.de>
Date: Wed, 25 Nov 2009 03:10:25 -0800 (PST)
Local: Wed, Nov 25 2009 6:10 am
Subject: Re: Why not datetime.utcnow() in auto_now/auto_now_add
On 25 Nov., 00:36, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

> Why would it be? A datetime field isn't necessarily stored in UTC. It
> uses datetime.now() because that will return the same time as
> settings.TIME_ZONE.

To improve my understanding: What if the server changed and the time
zone is not the same? IMHO the user can choose: 1. leave the
settings.TIME_ZONE to the old value, so all old datetimes are right,
but new datetimes are wrong. Or 2. he can update settings.TIME_ZONE
and old datetimes would be wrong, but new are right. Isn't it?

> On top of that, making this change would be a *huge* backwards
> incompatibility, as any existing uses of auto_now etc would break.

Yes. But it's easy to add a settings and the admin can choose between
now or utcnow. The default settings should be set utcnow.

Mfg.

Jens Diemer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Hudson  
View profile  
 More options Nov 25 2009, 1:52 pm
From: Rob Hudson <r...@cogit8.org>
Date: Wed, 25 Nov 2009 10:52:44 -0800
Local: Wed, Nov 25 2009 1:52 pm
Subject: Re: Why not datetime.utcnow() in auto_now/auto_now_add
On Tue, Nov 24, 2009 at 3:36 PM, Russell Keith-Magee

<freakboy3...@gmail.com> wrote:

> Time zone handling is definitely something that Django could handle
> better, but simply switching to UTC for certain functions isn't the
> solution.

I like the solution proposed on ticket 10587:
http://code.djangoproject.com/ticket/10587

Basically, it proposes that timezones are handled analogous to how
Unicode is handled -- that is, everything within Django boundaries is
treated as UTC, with timezone conversions happening on input and
output, but never within Django and always stored as UTC in the
database.

Ticket 10587 was closed as a duplicate of 2626, but I think 10587 has
the better description and proposal in it.

-Rob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Nov 25 2009, 7:08 pm
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Thu, 26 Nov 2009 08:08:54 +0800
Local: Wed, Nov 25 2009 7:08 pm
Subject: Re: Why not datetime.utcnow() in auto_now/auto_now_add

On Wed, Nov 25, 2009 at 7:10 PM, jedie <google.gro...@jensdiemer.de> wrote:
> On 25 Nov., 00:36, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
>> Why would it be? A datetime field isn't necessarily stored in UTC. It
>> uses datetime.now() because that will return the same time as
>> settings.TIME_ZONE.

> To improve my understanding: What if the server changed and the time
> zone is not the same? IMHO the user can choose: 1. leave the
> settings.TIME_ZONE to the old value, so all old datetimes are right,
> but new datetimes are wrong. Or 2. he can update settings.TIME_ZONE
> and old datetimes would be wrong, but new are right. Isn't it?

If the server changes, then it's up to the admin to manage that
change. Django *won't* make a change that will silently destroy the
integrity of existing databases in the field just by updating code,
which is *exactly* what changing to utcnow would do. Right now, there
are *thousands* of Django installations in the field - including many
of my own - that rely on the fact that auto_now uses datetime.now()
and returns a time localized to TIME_ZONE.

This behavior may be flawed, but it doesn't change the fact that this
is the way it currently is.

Storing datetimes in UTC may be a better default strategy, but that
doesn't change the way it currently is.

I am in complete agreement that Django should have better support for
time zones. As Rob Hudson pointed out, there is a long-standing ticket
requesting this (#2626). Changing the behavior of auto_now to return
utcnow doesn't address the larger problem.

>> On top of that, making this change would be a *huge* backwards
>> incompatibility, as any existing uses of auto_now etc would break.

> Yes. But it's easy to add a settings and the admin can choose between
> now or utcnow. The default settings should be set utcnow.

No, on two counts.

 1. Adding a setting to fix a problem doesn't fix a problem. It adds a
new problem.
 2. The existing value is datetime.now. *If* we were to add such a
setting (and let me tell you right now - we aren't going to), the
default value *must* be to use datetime.now - otherwise you don't get
backwards compatibility by default.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
k0001  
View profile   Translate to Translated (View Original)
 More options Dec 8 2009, 2:03 pm
From: k0001 <gnuk0...@gmail.com>
Date: Tue, 08 Dec 2009 16:03:20 -0300
Local: Tues, Dec 8 2009 2:03 pm
Subject: Re: Why not datetime.utcnow() in auto_now/auto_now_add

On Wed, 2009-11-25 at 10:52 -0800, Rob Hudson wrote:
> I like the solution proposed on ticket 10587:
> http://code.djangoproject.com/ticket/10587

> Basically, it proposes that timezones are handled analogous to how
> Unicode is handled -- that is, everything within Django boundaries is
> treated as UTC, with timezone conversions happening on input and
> output, but never within Django and always stored as UTC in the
> database.

I'm +1 on this idealistic solution.

But what about the backwards compatibility for already persisted dates
in a timezone different from UTC?

  signature.asc
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »