Opened 2 years ago

Closed 2 years ago

#29424 closed Bug (invalid)

Datetime objects parsed as strings when signals used - Django 1.9.5

Reported by: Adrian Castellanos Owned by: nobody
Component: Uncategorized Version:
Severity: Normal Keywords: signals model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Castellanos)

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):
post_save.connect(export_campaign_to_mongo, Campaign)

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

<class 'campaigns.models.Campaign'>
>>>from campaigns.models import Campaign
datetime.datetime(2016, 10, 10, 0, 0)

I am using Django v1.9.5.

Change History (2)

comment:1 Changed 2 years ago by Adrian Castellanos

Description: modified (diff)

comment:2 Changed 2 years ago by Simon Charette

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top