#30110: Specifying the primary key on an object with a datetimefield that has a
callable default results in the datetime parser trying to parse the
default, not the called default
-------------------------------------+-------------------------------------
Reporter: quindraco | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: datetimefield | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by quindraco):
* 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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.653f77f6c40d697d8cf1491c88cab29f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.