Opened 9 years ago
Closed 9 years ago
#26584 closed Bug (duplicate)
HStoreField reading broken from external script or console.
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
Change History (4)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Yes the bug seems have the same root with : #25454,
my apologies I Haven't found it during my search before posting this ticket.
'django.contrib.postgres' it is included, and the import of the modules happens at the startup of the script,
the bug can be easily replicated both from an external script both from the django shell.
this is the INSTALLED_APPS that I use:
INSTALLED_APPS = ( 'django.contrib.postgres', 'nested_admin', 'grappelli', 'django.contrib.auth', 'django.contrib.admin', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_extensions', 'rest_framework', .... 'wot.apps.website.alert' )
comment:4 by , 9 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This looks like a duplicate of #25454.
Is
'django.contrib.postgres'
in yourINSTALLED_APPS
? Are you issuing database query at module import time?