Saturday, April 7, 2012

Re: Django 1.4: TypeError: get_db_prep_value() got an unexpected keyword argument 'connection'

Hi,

What you've hit here is the end of the deprecation cycle for code that doesn't support multiple databases.

In Django 1.2, we introduced multiple database support; in order to support this, the prototype for get_db_preb_lookup() and get_db_prep_value() was changed.

For backwards compatibility, we added a shim that would transparently 'fix' these methods if they hadn't already been fixed by the developer.

In Django 1.2, the usage of these shims raised a PendingDeprecationWarning. In Django 1.3, they raised a DeprecationWarning.

Under Django 1.4, the shim code was been removed -- so any code that wasn't updated will now raise errors like the one you describe.

All the core Django fields should have been updated to use the new signature, so if you're seeing errors, it's probably because of a custom field that you're using that needs to be updated. As far as I can make out, Django's default ImageField shouldn't have this problem (it doesn't even have db_prep_* methods, because there's nothing database specific about the storage of FileFields).

If you can reproduce this on a project that only uses Django's built-in field types, then this is a bug in Django that needs to be addressed.

Yours
Russ Magee %-)


On Saturday, 7 April 2012 at 12:03 PM, xthepoet wrote:

> This was working fine for my Ubuntu 10.04LTE system with Django
> 1.3.1. It seems broken now in 1.4.
>
> In Django 1.4, I get this error TypeError: get_db_prep_value() got an
> unexpected keyword argument 'connection' when saving an image to an
> ImageField.
>
> System (installed from Ubuntu Lucid repository packages):
> Django 1.4
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
>
> The model field is defined as: origin_image =
> models.ImageField(upload_to='images/origin')
> The offending call is: obj.origin_image.save(fbFileName,
> ContentFile(input_file.getvalue()))
>
> Traceback (most recent call last):
> File "/home/seeker/src/ceeq/seekerapp/management/commands/
> addUser.py", line 100, in addPhotos
> obj.origin_image.save(fbFileName,
> ContentFile(input_file.getvalue()))
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/fields/files.py", line 95, in save
> self.instance.save()
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/base.py", line 463, in save
> self.save_base(using=using, force_insert=force_insert,
> force_update=force_update)
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/base.py", line 551, in save_base
> result = manager._insert([self], fields=fields,
> return_id=update_pk, using=using, raw=raw)
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/manager.py", line 203, in _insert
> return insert_query(self.model, objs, fields, **kwargs)
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/query.py", line 1576, in insert_query
> return query.get_compiler(using=using).execute_sql(return_id)
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/sql/compiler.py", line 909, in execute_sql
> for sql, params in self.as_sql():
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/sql/compiler.py", line 872, in as_sql
> for obj in self.query.objs
> File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> django/db/models/fields/__init__.py", line 292, in get_db_prep_save
> prepared=False)
> TypeError: get_db_prep_value() got an unexpected keyword argument
> 'connection'
>
> This problem was also reported on the django-celery board:
> https://github.com/ask/celery/issues/624
> But I've realized that for me, it's not a celery issue.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com (mailto:django-users+unsubscribe@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate