[Django] #29424: Datetime objects parsed as strings when signals used - Django 1.9.5

8 views
Skip to first unread message

Django

unread,
May 21, 2018, 9:26:07 AM5/21/18
to django-...@googlegroups.com
#29424: Datetime objects parsed as strings when signals used - Django 1.9.5
-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Castellanos |
Type: Bug | Status: new
Component: | Version:
Uncategorized |
Severity: Normal | Keywords: signals model
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I found a strange behavior when accesing objects models using signals. The
model is declared as:

{{{
class Campaign(models.Model):
start_stay_date = models.DateTimeField(null=True, blank=True)
end_stay_date = models.DateTimeField(null=True, blank=True)
}}}

When I use signals to connect the changes of the model with a function, a
found that the instance that is passed as argument has strings instead of
datetime in the dates:

The code of the conection between the model and the function is:

{{{
def export_campaign_to_mongo(sender, instance, *args, **kwargs):
check_dates()
post_save.connect(export_campaign_to_mongo, Campaign)
}}}

This is the output of the console checking the types of the objects:

{{{
>>>type(instance)
<class 'campaigns.models.Campaign'>
>>>instance.start_date
'2018-04-11T00:00:00'
>>>from campaigns.models import Campaign
>>>Campaign.objects.first().start_date
datetime.datetime(2016, 10, 10, 0, 0)
}}}

I am using Django v1.9.5.

--
Ticket URL: <https://code.djangoproject.com/ticket/29424>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 21, 2018, 9:29:51 AM5/21/18
to django-...@googlegroups.com
#29424: Datetime objects parsed as strings when signals used - Django 1.9.5
------------------------------------+--------------------------------------
Reporter: Adrian Castellanos | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version:
Severity: Normal | Resolution:
Keywords: signals model | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Description changed by Adrian Castellanos:

Old description:

> I found a strange behavior when accesing objects models using signals.
> The model is declared as:
>
> {{{
> class Campaign(models.Model):
> start_stay_date = models.DateTimeField(null=True, blank=True)
> end_stay_date = models.DateTimeField(null=True, blank=True)
> }}}
>
> When I use signals to connect the changes of the model with a function, a
> found that the instance that is passed as argument has strings instead of
> datetime in the dates:
>
> The code of the conection between the model and the function is:
>
> {{{
> def export_campaign_to_mongo(sender, instance, *args, **kwargs):
> check_dates()
> post_save.connect(export_campaign_to_mongo, Campaign)
> }}}
>
> This is the output of the console checking the types of the objects:
>
> {{{
> >>>type(instance)
> <class 'campaigns.models.Campaign'>
> >>>instance.start_date
> '2018-04-11T00:00:00'
> >>>from campaigns.models import Campaign
> >>>Campaign.objects.first().start_date
> datetime.datetime(2016, 10, 10, 0, 0)
> }}}
>
> I am using Django v1.9.5.

New description:

I found a strange behavior when accesing objects models using signals. The
model is declared as:

{{{
class Campaign(models.Model):
start_date = models.DateTimeField(null=True, blank=True)
end_date = models.DateTimeField(null=True, blank=True)
}}}

When I use signals to connect the changes of the model with a function, a
found that the instance that is passed as argument has strings instead of
datetime in the dates:

The code of the conection between the model and the function is:

{{{
def export_campaign_to_mongo(sender, instance, *args, **kwargs):
check_dates()
post_save.connect(export_campaign_to_mongo, Campaign)
}}}

This is the output of the console checking the types of the objects:

{{{
>>>type(instance)
<class 'campaigns.models.Campaign'>
>>>instance.start_date
'2018-04-11T00:00:00'
>>>from campaigns.models import Campaign
>>>Campaign.objects.first().start_date
datetime.datetime(2016, 10, 10, 0, 0)
}}}

I am using Django v1.9.5.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29424#comment:1>

Django

unread,
May 21, 2018, 9:49:37 AM5/21/18
to django-...@googlegroups.com
#29424: Datetime objects parsed as strings when signals used - Django 1.9.5
------------------------------------+--------------------------------------
Reporter: Adrian Castellanos | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version:
Severity: Normal | Resolution: invalid
Keywords: signals model | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => invalid


Comment:

Hello Adrian,

This has little to do with signals. If you create a `Campaign` object by
assigning a string value to `start_date` it will keep it for the duration
of its lifetime, it isn't converted to a `datetime` object on assignment.

In general, please direct such questions to the available help channels. I
am closing this ticket as invalid, for more details see
TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/29424#comment:2>

Reply all
Reply to author
Forward
0 new messages