Django

Code

Ticket #572 (closed: invalid)

Opened 4 years ago

Last modified 2 years ago

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

Reported by: lawgon@thenilgiris.com Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: cmlenz@gmx.de Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Attachments

Change History

09/28/05 06:55:59 changed by jacob

What's the error?

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

01/01/06 04:59:34 changed 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

01/01/06 17:20:03 changed by Tim

  • version set to SVN.

02/20/06 20:12:15 changed by mattycakes@gmail.com

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.

02/21/06 01:32:37 changed by Christopher Lenz <cmlenz@gmx.de>

  • cc set to cmlenz@gmx.de.

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

04/21/06 01:25:45 changed 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.

02/26/07 10:42:36 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Unreviewed to Accepted.

02/26/07 11:17:11 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(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.

(follow-up: ↓ 13 ) 03/01/07 11:29:25 changed by Babbage Linden

  • status changed from closed to reopened.
  • resolution deleted.

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.

03/01/07 11:30:50 changed by anonymous

  • status changed from reopened to closed.
  • resolution set to fixed.

03/01/07 11:39:11 changed by mir@noris.de

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

03/01/07 13:46:26 changed by SmileyChris

  • status changed from closed to reopened.
  • resolution deleted.

(in reply to: ↑ 9 ) 03/01/07 18:47:43 changed by Gary Wilson <gary.wilson@gmail.com>

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]?

05/22/07 09:09:07 changed by Brian Rosner <brosner@gmail.com>

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

05/22/07 17:23:18 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to invalid.

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.


Add/Change #572 (When i have an ImageField and a auto_now DateTimeField in the same model it doesnt get saved)




Change Properties
Action