Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#10453 closed (fixed)

get_db_prep_value called with seralized data

Reported by: brian Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



In order to resolve the difficulties encountered by ticket #10028, I installed the latest code from the 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)



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>
  File "./import", line 663, in main
  File "./import", line 438, in process_all
  File "/home/brian/myproject/lintory/inventory/", line 160, in update_last_seen
  File "/home/brian/tree/django/django/db/models/", line 329, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/home/brian/tree/django/django/db/models/", line 380, in save_base
    rows = manager.filter(pk=pk_val)._update(values)
  File "/home/brian/tree/django/django/db/models/", line 434, in _update
  File "/home/brian/tree/django/django/db/models/sql/", line 239, in add_update_fields
    val = field.get_db_prep_save(val)
  File "/home/brian/tree/django/django/db/models/fields/", line 192, in get_db_prep_save
    return self.get_db_prep_value(value)
  File "/home/brian/myproject/lintory/", 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/
  • Line 239 of db/models/sql/

Brian May

Change History (2)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

I'm thinking this is probably fixed by r10013 (trunk) and r10014 (1.0.X). If not, can you please reopen with a step-by-step to repeating the problem (preferably a patch against the tests that fail, but if not, at least something we can repeat).

comment:2 Changed 7 years ago by brian

Yes, just to confirm, it is fixed now. Thanks.

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