class foo(models.Model):
bar = models.DateTimeField(default=timezone.now)
f = foo(id=1)
f.save()
}}}
Will result in this:
{{{
TypeError: expected string or bytes-like object
}}}
This is thrown in django/utils/dateparse.py, in parse_datetime, at
{{{
match = datetime_re.match(value)
}}}
I did some digging, and the value is the default callable (here, the
timezone.now function). If you do the same thing without specifying the
primary key, it works as expected (calling the callable). Whether or not
you specify a value for the datetimefield in question does not appear to
matter. I have not tested with other field types.
--
Ticket URL: <https://code.djangoproject.com/ticket/30110>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Nasir Hussain):
Replying to [ticket:30110 quindraco]:
Hi, which python and database are you using? I tried with python 3.6.7,
django 2.1 and postgress and It worked fine for me.
--
Ticket URL: <https://code.djangoproject.com/ticket/30110#comment:1>
* status: new => closed
* resolution: => invalid
Old description:
> Assuming everything else is set up for your app, and an empty table for
> the model, this:
> {{{
> from django.db import models
> from django.utils import timezone
>
> class foo(models.Model):
> bar = models.DateTimeField(default=timezone.now)
> f = foo(id=1)
> f.save()
> }}}
>
> Will result in this:
>
> {{{
> TypeError: expected string or bytes-like object
> }}}
>
> This is thrown in django/utils/dateparse.py, in parse_datetime, at
> {{{
> match = datetime_re.match(value)
> }}}
>
> I did some digging, and the value is the default callable (here, the
> timezone.now function). If you do the same thing without specifying the
> primary key, it works as expected (calling the callable). Whether or not
> you specify a value for the datetimefield in question does not appear to
> matter. I have not tested with other field types.
New description:
Assuming everything else is set up for your app, and an empty table for
the model, this:
{{{
from django.db import models
from django.utils import timezone
class foo(models.Model):
bar = models.DateTimeField(default=timezone.now)
f = foo(id=1)
f.save()
}}}
Will result in this:
{{{
TypeError: expected string or bytes-like object
}}}
This is thrown in django/utils/dateparse.py, in parse_datetime, at
{{{
match = datetime_re.match(value)
}}}
I did some digging, and the value is the default callable (here, the
timezone.now function). If you do the same thing without specifying the
primary key, it works as expected (calling the callable). Whether or not
you specify a value for the datetimefield in question does not appear to
matter. I have not tested with other field types.
Versions:
--
Comment:
....ah. I was using an out of date version. I'll set this bug to
invalid. Sorry about that. Could have sworn I checked that.
--
Ticket URL: <https://code.djangoproject.com/ticket/30110#comment:2>