Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register_hstore_handler is not run during django management commands #141

Open
GooseYArd opened this issue Dec 10, 2015 · 6 comments
Open

Comments

@GooseYArd
Copy link

Hi All,

I'm experiencing the same problem as issue #93, I'm not a postgis user though, and neither of the two suggested settings workarounds seem to affect my issue, which occurs when running a Django management command that uses a couple of models that contain hstore fields. I'm using Django 1.8.6, django_hstore 1.4.1 and psycopg2 2.6.1.

I've confirmed that the hstore oids are consistent among the databases, and then did a little printf debugging. I found that register_hstore_handler is never called, but that I can fix the str-instead-of-dict problem by explicitly calling psycopg2.extras.register_hstore during the management command's constructor.

We don't use the transaction middleware, but do have a number of other middlewares enabled that I presume could affect signal delivery in the same way.

I'd like to provide more useful information in the issue request, but at the moment I'm not sure what to check next- any advice appreciated.

@sanchitsharma
Copy link

I am too facing the same issue. Can you elaborate a bit on how you are solving the issue for now .i.e (where do you get the connection object to pass in the register_hstore function)

@clifff
Copy link

clifff commented Feb 23, 2016

I ran into this problem too - in both manage.py shell and in a mangement command, I'd get ProgrammingError: can't adapt type 'HStoreDict' errors every time I tried to create a model instance with an Hstore field.

@sanchitsharma: I worked around it by adding this to my management command:

from django.db import connection
from psycopg2.extras import register_hstore
# And then in `def handle`
register_hstore(connection.cursor(), globally=True, unicode=True)

@nemesifier
Copy link
Member

is django_hstore in your settings.INSTALLED_APPS?

@chuck
Copy link

chuck commented Dec 14, 2016

I'm suddenly seeing this after upgrading from Django 1.7 to Django 1.8.17 (and from django-hstore 1.4 to 1.4.2, though not surprisingly reverting that minor upgrade doesn't change anything).

django_hstore is in settings.INSTALLED_APPS. Fiddling with the order of INSTALLED_APPS hasn't resulted in any improvement.

I don't have a small reproducible case, but I'm happy to debug. The workaround described by @clifff works for me, but would of course be pretty ugly to add to every management command.

@DustinHolden
Copy link

I just started using django_hstore with a project and am encountering this same issue, and the workaround worked for me. Just curious if anyone had any more information on this before I started digging into it?

Django 1.8.18, django_hstore 1.4.2.

@chuck
Copy link

chuck commented Sep 26, 2017

@DustinHolden which workaround worked for you? I have one that works in shell/shell_plus, but I haven't figured out how to incorporate it into migration generation, which is a constant pain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants