[Django] #23776: HStoreField example doesn't work

19 views
Skip to first unread message

Django

unread,
Nov 7, 2014, 8:16:53 AM11/7/14
to django-...@googlegroups.com
#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.

Django

unread,
Nov 7, 2014, 10:11:52 AM11/7/14
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: postgres hstore | Unreviewed
register | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Did you add `'django.contrib.postgres'` to `INSTALLED_APPS`? That should
set things up I believe.

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:1>

Django

unread,
Nov 8, 2014, 2:34:43 AM11/8/14
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: postgres hstore | Unreviewed
register | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by vedgar):

Yes, that's one of first things I did. It didn't help.

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:2>

Django

unread,
Nov 8, 2014, 9:12:16 AM11/8/14
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: postgres hstore | Unreviewed
register | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by apollo13):

@vedgar: Can you try remplacing pass with raise in
https://github.com/django/django/blob/master/django/contrib/postgres/signals.py#L16-L25
?

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:3>

Django

unread,
Nov 12, 2014, 7:33:17 AM11/12/14
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: postgres hstore | Unreviewed
register | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by vedgar):

Hm, I changed pass to raise and it worked. Since that didn't make any
sense, I changed it back and it still works. I updated django to latest
before that, so maybe it was fixed. But it's possible that I made a
mistake earlier - sorry for bothering you.

(Just out of curiosity: when makemigrations says "No changes detected", or
migrate says "No migrations to apply", is it still possible that something
happened to my app? For instance, hstore was registered or something like
that.:)

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:4>

Django

unread,
Nov 12, 2014, 7:49:21 AM11/12/14
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: postgres hstore | Triage Stage:
register | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => worksforme


--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:5>

Django

unread,
Sep 23, 2016, 2:27:02 AM9/23/16
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: postgres hstore | Triage Stage:
register | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Sassan Haradji):

I had to run `CREATE EXTENSION hstoredict` in Postgres shell. Before that
it raised the above error even though I had `'django.contrib.postgres'` in
`INSTALLED_APPS`.

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:6>

Django

unread,
Sep 23, 2016, 2:28:20 AM9/23/16
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:

Keywords: postgres hstore | Triage Stage:
register | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sassan Haradji):

* status: closed => new
* resolution: worksforme =>


--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:7>

Django

unread,
Sep 23, 2016, 8:08:04 AM9/23/16
to django-...@googlegroups.com
#23776: HStoreField example doesn't work
-------------------------------------+-------------------------------------
Reporter: vedgar | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution:
| worksforme

Keywords: postgres hstore | Triage Stage:
register | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed

* component: Database layer (models, ORM) => Documentation
* resolution: => worksforme


Comment:

That step is documented, "Setup the hstore extension in PostgreSQL before
the first CreateModel or AddField operation by adding a migration with the
HStoreExtension operation. "

--
Ticket URL: <https://code.djangoproject.com/ticket/23776#comment:8>

Reply all
Reply to author
Forward
0 new messages