Opened 11 years ago

Closed 11 years ago

#21577 closed Bug (duplicate)

to_python() of django.db.models.fields.__init__.DateField not detecting datetime.date type

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: db database model date datetime dateparse to_python
Cc: Matt C Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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):

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?

Change History (2)

comment:1 by Matt C, 11 years ago

Cc: Matt C added

comment:2 by Aymeric Augustin, 11 years ago

Resolution: duplicate
Status: newclosed

The symptoms reported here are identical to #21523.

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