Code

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3260 closed defect (invalid)

inserting date filed value into MySQL

Reported by: satya sunkara Owned by: adrian
Component: Core (Other) Version: 0.95
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi ,

We are inserting Date field into a MySQL database using a Django form.

Since the form field returns a string representation of Date we are doing the following conversion in our view.

t1=strptime(request.POSTstartdate?,"%Y-%m-%d")
t2=strftime("%Y-%m-%d",t1)

and then invoking the model like this

p = project.objects.create(entity_id=e.id,name=request.POSTproject_name?,description=request.POSTDescription?,startdate=t2,acronym=request.POSTacronym?)

We are getting the following error*

AttributeError at /startapp/saveproject/
'str' object has no attribute 'strftime'
Request Method: POST
Request URL: http://127.0.0.1:8000/startapp/saveproject/
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'strftime'
Exception Location: C:\WorkArea\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\fields\init.py in get_db_prep_save, line 451

After googling around I found that this error is similar to the error in Ticket# 2192

The ticket 2192 was fixed ,but it seems you need to fix the line 449 in fields\init.py

I have temporarily added a following fix at 449 and it worked!!!!

if value is not None and settings.DATABASE_ENGINE != 'mysql':

if value is not None :

value = value.strftime('%Y-%m-%d')
return Field.get_db_prep_save(self, value)

else:

return Field.get_db_prep_save(self, value)

Attachments (0)

Change History (4)

comment:1 Changed 7 years ago by anonymous

Actually my fix is like this

if value is not None and settings.DATABASE_ENGINE != 'mysql':

value = value.strftime('%Y-%m-%d')
return Field.get_db_prep_save(self, value)

else:

return Field.get_db_prep_save(self, value)

comment:2 follow-up: Changed 7 years ago by Simon G. <dev@…>

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

Can we get a test case to confirm this as an issue?

comment:3 in reply to: ↑ 2 ; follow-up: Changed 7 years ago by lutz@…

Replying to Simon G. <dev@simon.net.nz>:

Can we get a test case to confirm this as an issue?

I don't know what test case you would like to have, but above fix helped me.

comment:4 in reply to: ↑ 3 Changed 7 years ago by mir@…

Replying to lutz@users.sourceforge.net:

Replying to Simon G. <dev@simon.net.nz>:

Can we get a test case to confirm this as an issue?

I don't know what test case you would like to have, but above fix helped me.

A test case is needed so that

  • the triage team can easily verify that the bug still exists. For this, multiple reports are probably sufficient
  • the developers can find out what's happening and also can easily verify that their fix really solves your problem.

For this, a test case needs to be a step-by-step instruction including all needed models and data, so that when someone else follows them, they will get the same error.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.