Opened 9 years ago
Last modified 9 years ago
#26584 closed Bug
HStoreField reading broken from external script or console. — at Version 1
Reported by: | Dario Deledda | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | HStoreField register_hstore |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Bug Description
When you run from external script or console the reading of an HStoreField return a String instead a Dict.
for example: an object from a class like:
class Alert(models.Model): data = HStoreField(default={})
if you try:
a=Alert.objects.all()[0 type(a.data)
return <class 'str'>
instead <class 'dict'>
Brief analysis
It seems that in the console or script init, the register_hstore it's not called.
WorkAround:
If you use for the init of the console or external script the following code:
sys.path.append(gDjangoProjectPath) os.environ["DJANGO_SETTINGS_MODULE"] = gDjangoSetting django.setup() from django.contrib.postgres.fields import HStoreField from wot.apps.website.alert import Alert # HSTORE BUG WORK AROUND!! from django.db import connection from psycopg2.extras import register_hstore register_hstore(connection.connection)
the HStoreField work normally.
pip Freeze
modules versions used for the test.
aiohttp==0.21.5 arrow==0.7.0 chardet==2.3.0 defusedxml==0.4.1 Django==1.8.12 django-allauth==0.25.2 django-braces==1.8.1 django-extensions==1.6.1 django-filter==0.13.0 django-grappelli==2.8.1 django-nested-admin==3.0.2 djangorestframework==3.3.3 eventlet==0.18.4 gevent==1.1.1 greenlet==0.4.9 gunicorn==19.4.5 Markdown==2.6.6 oauthlib==1.0.3 Pillow==3.2.0 psycopg2==2.6.1 pyinotify==0.9.6 python-dateutil==2.5.3 python-monkey-business==1.0.0 python-redmine==1.5.1 python3-openid==3.0.10 pytz==2016.4 reportlab==3.3.0 requests==2.9.1 requests-oauthlib==0.6.1 setproctitle==1.1.9 six==1.10.0 stripe==1.32.2 tinycss==0.3
Note:
See TracTickets
for help on using tickets.