#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Keywords: postgres hstore
Severity: Normal | register
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
From https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields
/#querying-hstorefield
With given model (Dog), in shell,
{{{
>>> from atest.models import Dog
>>> Dog.objects.create(name='Rufus', data={'breed': 'labrador'})
}}}
gives "can't adapt type 'dict'" error. After researching, it seems to me
it's because noone called psycopg2.extras.register_hstore, that must be
called to enable storing dict as hstore in a Postgres database. (If
django_hstore is in the list of INSTALLED_APPS, it will call
register_hstore by itself, which is probably why it works for some people.
But once you remove django_hstore from INSTALLED_APPS, you'll see the bug.
Since django_hstore is external app, Django probably shouldn't rely on
it.)
I'm not quite sure how to fix it, since I don't know who should be
responsible for registering hstore... there is a HStoreExtension operation
that does it when migrating, but I have a feeling it should be inserted
automatically from makemigrations (when app uses hstore), not shift the
burden on users. Even if users are expected to register hstore manually,
it should be clearly stated in the docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/23776>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.11dcff2327883e9cc8b29bf1383ba940%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.