#25454: Problem using HStoreField in django shell
----------------------------------+-------------------------
Reporter: reichert | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Keywords: hstorefield
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------
Using hstorefield through the webserver works fine, but for applications
that don't use the webserver like management commands we got a problem
with models that use hstorefield. Among these problems is retrieving the
hstorefield object which is retrieved as 'str' insteado of a 'dict'.
I found out a workaround that may be the cause of the bug but I've not
enought knowledge to propose a fix.
Here is how to replicate the problem:
{{{
# subaccount is a hstorefield of AccountEntry model
In [8]: entry = AccountEntry.objects.get(pk=1)
In [9]: entry.subaccount
Out[9]: '"store"=>"velocity"'
In [10]: entry.subaccount.__class__
Out[10]: str
}}}
To get it working I'd to do this trick:
{{{
In [12]: from psycopg2.extras import register_hstore
In [13]: from django.db import connection
In [14]: register_hstore(connection.connection, globally=True,
unicode=True)
In [15]: entry.subaccount
Out[15]: '"store"=>"velocity"'
In [16]: entry2 = AccountEntry.objects.get(pk=2)
In [17]: entry2.subaccount
Out[17]: {u'store': u'velocity'}
In [18]: entry2.subaccount.__class__
Out[18]: dict
}}}
Note that:
1) We are using django 1.8.4, python 2.7.9, psycopg2 2.6.1, postgresql
9.4.4
2) We installed the hstore extension in the template1 and we have created
the django database after the hstore extension creation.
3) We have in our INSTALLED_APPS the django.contrib.postresql
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/25454>
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/051.225d7df362ac735bd2f7729fecbf7a7e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.