DateTimeField TypeError: replace() takes no keyword arguments?

4,727 views
Skip to first unread message

jtm

unread,
Aug 20, 2005, 10:29:43 AM8/20/05
to Django users
This one has me stumped.

I have a mySession class with three DateTimeFields along these lines:

meta.DateTimeField('session_start', 'Session Start Time',
auto_now_add=True)

when I create a new mySession instance and try to .save() it, I get the
following Traceback:

Traceback (most recent call last):

File "D:\python24\lib\site-packages\django\core\handlers\base.py",
line 64, in get_response
response = callback(request, **param_dict)

File "D:\python24\lib\site-packages\dcm\apps\survey\views\survey.py",
line 110, in checkLogin
sess.save()

File "D:\python24\lib\site-packages\django\utils\functional.py", line
3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File "D:\python24\lib\site-packages\django\core\meta\__init__.py",
line 739, in method_save
db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.name),
False)) for f in non_pks]

File "D:\python24\lib\site-packages\django\core\meta\fields.py", line
308, in get_db_prep_save
value = value.replace(microsecond=0)

TypeError: replace() takes no keyword arguments


Anyone have any hints about this? I fiddled a little, like putting an
"if not isinstance(value, datetime.datetime): raise TypeError" kind of
thing above line 308, and it was throwing the exception, but I have no
idea how to progress things from there.

Any tips on the best ways to get debugging output from django when
you're in the browser would be warmly received.

Thanks again,

jtm

Adrian Holovaty

unread,
Aug 20, 2005, 1:12:48 PM8/20/05
to django...@googlegroups.com
On 8/20/05, jtm <james.w...@gmail.com> wrote:
> I have a mySession class with three DateTimeFields along these lines:
>
> meta.DateTimeField('session_start', 'Session Start Time',
> auto_now_add=True)
> [...]
> File "D:\python24\lib\site-packages\django\core\meta\fields.py", line
> 308, in get_db_prep_save
> value = value.replace(microsecond=0)
>
> TypeError: replace() takes no keyword arguments
>
> Anyone have any hints about this? I fiddled a little, like putting an
> "if not isinstance(value, datetime.datetime): raise TypeError" kind of
> thing above line 308, and it was throwing the exception, but I have no
> idea how to progress things from there.

Yeah, it looks like the value is a string instead of a datetime object
at that point. How did you instantiate the object? Did you pass it
strings, or datetime objects, or did you rely on the auto_now_add?

> Any tips on the best ways to get debugging output from django when
> you're in the browser would be warmly received.

I've got Django integrated with pdb in my local copy of the
development server, and I'm just trying to figure out the smartest way
to do it. Currently it drops into pdb to handle all exceptions when I
launch django-admin.py runserver with the "--pdb" option -- but
ideally you wouldn't have to pass that, and it should automatically
ask you whether you wanted to drop into pdb.

Adrian

jtm

unread,
Aug 20, 2005, 7:22:24 PM8/20/05
to Django users
It's not Django, it's me.

Between the caffeine and lack of sleep and looming deadline, skimming
the Django documentation led me to believe that you attach foreign keys
like so:

a = aClass()
b = add_aClass(a)

where is I should have been saying:

a = aClass(b_id=b.id)

Unless there is another way to add foreign keys?

Thanks,

jtm

ska...@gmail.com

unread,
Aug 30, 2005, 1:30:05 AM8/30/05
to Django users
I ran into this exact same error today. I have an object with 2
dateTimeField's on is required and the other isn't. If I fill in the
first dateTime but leave the 2nd on blank then I get this error.

Here is a sample model:

from django.core import meta

class Event(meta.Model):
start_date = meta.DateTimeField('Start Date')
end_date = meta.DateTimeField('End Date', blank=True)

class META:
admin = meta.Admin()

def __repr__(self):
return self.start_da


and the error

There's been an error:

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py",


line 64, in get_response
response = callback(request, **param_dict)

File "/usr/lib/python2.4/site-packages/django/views/admin/main.py",
line 777, in add_stage
new_object = manipulator.save(new_data)

File "/usr/lib/python2.4/site-packages/django/utils/functional.py",


line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File "/usr/lib/python2.4/site-packages/django/core/meta/__init__.py",
line 1463, in manipulator_save
new_object.save()

File "/usr/lib/python2.4/site-packages/django/utils/functional.py",


line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File "/usr/lib/python2.4/site-packages/django/core/meta/__init__.py",
line 793, in method_save
db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column),
True)) for f in opts.fields if not isinstance(f, AutoField)]

File "/usr/lib/python2.4/site-packages/django/core/meta/fields.py",
line 333, in get_db_prep_save

Reply all
Reply to author
Forward
0 new messages