Opened 19 years ago

Closed 17 years ago

#572 closed defect (invalid)

When i have an ImageField and a auto_now DateTimeField in the same model it doesnt get saved

Reported by: lawgon@… Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: normal Keywords:
Cc: cmlenz@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When there is an image field and a auto_now_add date time field in the same table, the date time field is not generated although the image is uploaded, and a postgres error is generated

Change History (15)

comment:1 by Jacob, 19 years ago

What's the error?

Do you have a simplified model that you can reproduce the error on?

comment:2 by Tim, 18 years ago

I have (what I think to be) the same problem, it seems that if there's an ImageField it does not auto create the dates (stored as 0000-00-00 00:00:00). Removing the ImageField from the model and it all works fine.

Here's the error message:

Exception Type:  	ValueError
Exception Value: 	year is out of range
Exception Location: 	/usr/lib/python2.4/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 32

comment:3 by Tim, 18 years ago

Version: SVN

comment:4 by mattycakes@…, 18 years ago

I'm having what I assume is the same problem; I have a FileField in my model, and my auto_now_add=True DateField is being left blank, causing a "year is out of range" error.

comment:5 by Christopher Lenz <cmlenz@…>, 18 years ago

Cc: cmlenz@… added

This looks like it's closely related to #639.

comment:6 by Arthur Hebert, 18 years ago

I can reproduce the same error with no FileField or ImageField, but it still relates to auto_now_add=True. The following simple case shows this symptom in a strange way:

from django.core import meta
from django.models import persons


class One(meta.Model):
        my_field = meta.CharField(maxlength=20)

        def __repr__(self):
                return self.my_field

        class META:
                admin = meta.Admin()

class Two(meta.Model):
        a_field = meta.CharField(maxlength=20,core=True)
        forkey = meta.ForeignKey(One,edit_inline=meta.STACKED,num_in_admin=1)
        date_asked = meta.DateTimeField(auto_now_add=True)

In the admin, follow these steps (i'm using the word attached to imply the ForeignKey relationship):

1. Create an instance of '''One''' and save it with no attached instances of '''Two'''. 
2. Find the instance in the admin list and click on the link to edit it. 
3. Add an attached instance of '''Two''' with a value of ''foo'', and save it. 
4. Again find the instance in the admin list and click the link to edit.
5. Add a second attached instance of '''Two''' with value ''bar'', and save. 
6. Finally, try opening that link again in the list to edit the '''One''' object.

It produces an error page with the following heading (debug=on):

Request Method:  	GET
Request URL: 	http://datamine/admin/tests/ones/1/
Exception Type: 	ValueError
Exception Value: 	year is out of range
Exception Location: 	/usr/lib/python2.4/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 32

If you set auto_now_add=False, then the problem goes away. The problem also goes away if you use just a DateField instead of a DateTimeField. The error also goes away if you use auto_now instead of auto_now_add.

I hope this helps.

comment:7 by Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:8 by Jacob, 17 years ago

Resolution: fixed
Status: newclosed

(In [4609]) Objects with FileFields no longer get save() called multiple times from the AutomaticManipulator! This fixes #639, #572, and likely others I don't know of.

This may be slightly backwards-incompatible: if you've been relying on the multiple-save behavior (why?), then you'll no longer see that happen.

comment:9 by Babbage Linden, 17 years ago

Resolution: fixed
Status: closedreopened

I'm seeing similar behaviour with a model which has classes A and B, B has 2 ManyToManyField(A) relationships and both classes have created = DateTimeField(auto_now_add=True) fields. When I try to look at the details for an instance of A or B in the admin interface I get the "year is out of range" error. I'm running Django 0.95 against MySQL and Apache2 on an Ubuntu Breezy server.

comment:10 by anonymous, 17 years ago

Resolution: fixed
Status: reopenedclosed

comment:11 by mir@…, 17 years ago

Mr. Anonymous, please don't close tickets without giving a reason.

comment:12 by Chris Beaven, 17 years ago

Resolution: fixed
Status: closedreopened

in reply to:  9 comment:13 by Gary Wilson <gary.wilson@…>, 17 years ago

Replying to Babbage Linden:

I'm seeing similar behaviour with a model which has classes A and B, B has 2 ManyToManyField(A) relationships and both classes have created = DateTimeField(auto_now_add=True) fields.

Just to clarify, are you using a revision >= [4609]?

comment:14 by Brian Rosner <brosner@…>, 17 years ago

Isn't this now resolved since the removal of auto_now_add?

comment:15 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: reopenedclosed

Agreed, Brain. In light of changes to both file saving and removal of auto_now and auto_now_add, I'll close this as no longer valid. If a similar issue crops up with an example against trunk, we can open a new ticket.

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