HStoreField can't adapt type 'dict'

2,508 views
Skip to first unread message

Vedran Čačić

unread,
Nov 7, 2014, 3:17:31 AM11/7/14
to django...@googlegroups.com
I know it's very early release, but I'd expect the example from the docs to work. I started playing with HStoreField from django.contrib.postgres.fields, and get the error above. Model Dog is copied verbatim from https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#querying-hstorefield, and then in the shell, 

    >>> from atest.models import Dog
    >>> Dog.objects.create(name='Rufus', data={'breed': 'labrador'})
    ...
        return self.cursor.execute(sql, params)
    django.db.utils.ProgrammingError: can't adapt type 'dict'

At that moment,

    sql = 'INSERT INTO "atest_dog" ("name", "data") VALUES (%s, %s) RETURNING "atest_dog"."id"'
    params = ('Rufus', {'breed': 'labrador'})

So, everything should be completely normal - yet, HStoreField somehow doesn't know how to accept dict, despite docs saying that it's exactly what it should accept. Does anyone have any advice? Has anyone tried to do something with HStoreField?

Collin Anderson

unread,
Nov 12, 2014, 3:36:45 PM11/12/14
to django...@googlegroups.com
If anyone runs into this later, here's the ticket with the solution:

Fred Stluka

unread,
Nov 13, 2014, 11:29:30 AM11/13/14
to django...@googlegroups.com
Collin,

Your answers to so many questions lately have been very
helpful.  Thanks!

Any reason you don't include the original question with your
reply?  Either by top-posting, or by quoting an excerpt?

Would provide context to your answers, making them more
useful, especially to those of us reading them as email, not
at the Google Groups Web site.

Thanks!
--Fred
Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
On 11/12/14 3:36 PM, Collin Anderson wrote:
If anyone runs into this later, here's the ticket with the solution:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa827df7-abc4-41f6-b0b7-b947b2638396%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Nov 17, 2014, 3:37:23 PM11/17/14
to django...@googlegroups.com, fr...@bristle.com, FredS...@gmail.com
Hi Fred,

On Thursday, November 13, 2014 11:29:30 AM UTC-5, Fred Stluka wrote:
Any reason you don't include the original question with your
reply?  Either by top-posting, or by quoting an excerpt?
I like to keep the emails as short as possible :)

Would provide context to your answers, making them more
useful, especially to those of us reading them as email, not
at the Google Groups Web site.
I'll start doing that.

Thanks!
Collin

Reply all
Reply to author
Forward
0 new messages