﻿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
10453	get_db_prep_value called with seralized data	Brian May	nobody	"Hello,

In order to resolve the difficulties encountered by ticket #10028, I installed the latest code from the http://code.djangoproject.com/svn/django/branches/releases/1.0.X branch.

It appears that the behaviour of the ""get_db_prep_value"" function has changed, and the current behaviour seems wrong to me.

(note: actual function call is get_db_prep_save, but as this just calls get_db_prep_value I consider them the same)

From:

<http://docs.djangoproject.com/en/dev/howto/custom-model-fields/>


{{{
def get_db_prep_value(self, value):
        return ''.join([''.join(l) for l in (value.north,
                value.east, value.south, value.west)])
}}}

This would imply value should always be the python object returned by to_python.

It seems in my case, when calling save() on an object and this field is not updated, then value contains the raw un-serialized string data straight from the database.

I could work around this by checking if the value is a string, and if so, returning it as is, but to me this seems wrong.

Stack trace:

{{{
Traceback (most recent call last):
  File ""./import"", line 681, in <module>
    sys.exit(main())
  File ""./import"", line 663, in main
    host.process_all(force)
  File ""./import"", line 438, in process_all
    self.update_last_seen(self.datetime)
  File ""/home/brian/myproject/lintory/inventory/importer.py"", line 160, in update_last_seen
    self.computer.save()
  File ""/home/brian/tree/django/django/db/models/base.py"", line 329, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File ""/home/brian/tree/django/django/db/models/base.py"", line 380, in save_base
    rows = manager.filter(pk=pk_val)._update(values)
  File ""/home/brian/tree/django/django/db/models/query.py"", line 434, in _update
    query.add_update_fields(values)
  File ""/home/brian/tree/django/django/db/models/sql/subqueries.py"", line 239, in add_update_fields
    val = field.get_db_prep_save(val)
  File ""/home/brian/tree/django/django/db/models/fields/__init__.py"", line 192, in get_db_prep_save
    return self.get_db_prep_value(value)
  File ""/home/brian/myproject/lintory/names.py"", line 188, in get_db_prep_value
    return value.get_value()
AttributeError: 'str' object has no attribute 'get_value'
}}}


From this stack trace, it would appear that get_db_prep_save is called twice for the same data:

 * Line 379 of django/db/models/base.py
 * Line 239 of db/models/sql/subqueries.py

Brian May"		closed	Database layer (models, ORM)	1.0		fixed			Unreviewed	0	0	0	0	0	0
