Opened 17 years ago

Closed 17 years ago

#5752 closed (invalid)

DateTime fields with default=datetime.now don't fill properly in model.AddManipulator

Reported by: Wesley Fok <portland@…> Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is all happening under Django SVN 5819.

Say I have an Entry model like so:

class Entry(models.Model):
    title = models.CharField(maxlength=255)
    content = models.TextField()
    is_published = models.BooleanField(default=True)
    date_published = models.DateTimeField(default=datetime.now(), blank=None, null=None)

which is hooked into the create_object generic view (not directly, but via a custom view that eventually returns create_object). What I would expect in the ensuing form is two fields for date and time, where the date and time reflect the current date and time. Shift-reloading that page should refresh the time so that it's always current. Instead, what happens is the time bounces back and forth between two times, neither of which are the current time; they are both times in the near past.

This is not a browser refresh problem; some digging revealed that the problem occurs even when you attempt to query the model's AddManipulator object:

>>> from datetime import datetime
>>> from journal.blog.models import Entry
>>> datetime.now()
datetime.datetime(2007, 10, 14, 5, 20, 28, 863454)
>>> Entry.AddManipulator().flatten_data()['date_published_time']
'05:19:52'
>>> datetime.now()
datetime.datetime(2007, 10, 14, 5, 22, 1, 45406)
>>> Entry.AddManipulator().flatten_data()['date_published_time']
'05:19:52'

Three minutes has passed since the Entry import, but the time in the Manipulator hasn't changed. It also doesn't change if I re-import Entry as Entry2 and try again. In fact, the only thing that changes the time is creating a new Python shell and importing Entry. In fact, the time seems to reflect the initial import of the Entry model into the Python environment. This doesn't seem like desirable behaviour.

My guess is that on the web form, the date shows one of two times because I'm currently running an Apache/mod_python setup with the ServerLimit set to 2; every time the date_published time changes, I'm on a different server instance. The times refresh occasionally, which I expect is due to an Apache child instance being recycled after hitting MaxRequestsPerChild.

Unfortunately I have no idea where to start to fix this, and because this all falls under the oldforms framework I don't know if it'll ever be fixed, but I leave that to the Django gods.

Change History (1)

comment:1 by Wesley Fok <portland@…>, 17 years ago

Resolution: invalid
Status: newclosed

Erm, ha ha, my bad, I just saw the note about using datetime.now instead of datetime.now(). I am awesome.

Note: See TracTickets for help on using tickets.
Back to Top