Opened 10 years ago

Closed 8 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
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: cmlenz@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 Changed 10 years ago by jacob

What's the error?

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

comment:2 Changed 9 years ago by Tim

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 Changed 9 years ago by Tim

  • Version set to SVN

comment:4 Changed 9 years ago by mattycakes@…

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 Changed 9 years ago by Christopher Lenz <cmlenz@…>

  • Cc cmlenz@… added

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

comment:6 Changed 9 years ago by Arthur Hebert

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 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:8 Changed 8 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(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 follow-up: Changed 8 years ago by Babbage Linden

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 Changed 8 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

comment:11 Changed 8 years ago by mir@…

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

comment:12 Changed 8 years ago by SmileyChris

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:13 in reply to: ↑ 9 Changed 8 years ago by Gary Wilson <gary.wilson@…>

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 Changed 8 years ago by Brian Rosner <brosner@…>

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

comment:15 Changed 8 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from reopened to closed

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