Opened 8 years ago

Closed 8 years ago

#21577 closed Bug (duplicate)

to_python() of django.db.models.fields.__init__.DateField not detecting 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


Stack trace of exception:

Traceback (most recent call last):

  ...db model save() call...

  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 545, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", 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/", line 635, in _save_table
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 679, in _do_update
    return filtered._update(values) > 0
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", 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/", 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/", line 771, in execute_sql
    sql, params = self.as_sql()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", 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/", line 350, in get_db_prep_save
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/", 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/", line 798, in get_prep_value
    return self.to_python(value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/", line 756, in to_python
    parsed = parse_date(value)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/", 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 and it is "" type, where it should be of a string type. So if the type is "", 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,

The strange thing is that I only have this issue when running " 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 Changed 8 years ago by Matt C

Cc: Matt C added

comment:2 Changed 8 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

The symptoms reported here are identical to #21523.

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