﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21577	to_python() of django.db.models.fields.__init__.DateField not detecting datetime.date type	anonymous	nobody	"Stack trace of exception:

{{{
Traceback (most recent call last):

  ...db model save() call...

  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/base.py"", line 545, in save
    force_update=force_update, update_fields=update_fields)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/base.py"", line 573, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/base.py"", line 635, in _save_table
    forced_update)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/base.py"", line 679, in _do_update
    return filtered._update(values) > 0
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/query.py"", line 507, in _update
    return query.get_compiler(self.db).execute_sql(None)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py"", line 975, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py"", line 771, in execute_sql
    sql, params = self.as_sql()
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py"", line 940, in as_sql
    val = field.get_db_prep_save(val, connection=self.connection)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py"", line 350, in get_db_prep_save
    prepared=False)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py"", line 803, in get_db_prep_value
    value = self.get_prep_value(value)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py"", line 798, in get_prep_value
    return self.to_python(value)
  File ""/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py"", line 756, in to_python
    parsed = parse_date(value)
  File ""/usr/local/lib/python2.7/dist-packages/django/utils/dateparse.py"", line 36, in parse_date
    match = date_re.match(value)
TypeError: expected string or buffer
}}}

Database backend: PostgreSQL 9.1.1
OS: Ubuntu 13.10 x86_64
Python version: 2.7.5+

I titled this ticket saying the problem is in the to_python() method of django.db.models.fields.`__`init`__`.DateField, because I did some investigation myself and analysed the type of the variable named ""value"" in parse_date() of dataparse.py and it is ""datetime.date"" type, where it should be of a string type. So if the type is ""datetime.date"", then why isn't the check on line 752 of django.db.models.fields.`__`init`__`.DateField passing?

The line in question (752 of django.db.models.fields.`__`init`__`.DateField):
{{{#!python
if isinstance(value, datetime.date):
}}}

The strange thing is that I only have this issue when running ""manage.py test"" and running all my unit test files. If I run a single unit test file via the pattern flag ""-p"" on a test file where an exception is stemming from, it runs fine. Also, running my application does not produce any of these exceptions, so it's only running all the unit test files.

Any ideas what is causing this?"	Bug	closed	Database layer (models, ORM)	1.6	Normal	duplicate	db database model date datetime dateparse to_python	Matt C	Unreviewed	0	0	0	0	0	0
