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

HSTORE adapter registration in psycopg2 conflicts with SQLAlchemy #45

Closed
gthb opened this issue May 16, 2014 · 9 comments
Closed

HSTORE adapter registration in psycopg2 conflicts with SQLAlchemy #45

gthb opened this issue May 16, 2014 · 9 comments

Comments

@gthb
Copy link

gthb commented May 16, 2014

If both django_hstore and SQLAlchemy are used in the same Python process with psycopg2, then django_hstore's adapter registration will cause psycopg2 to return HStoreDict instances to SQLAlchemy, which expects str. This causes errors like AttributeError: 'HStoreDict' object has no attribute 'decode' in sqlalchemy/dialects/postgresql/hstore.py:

    def process(value):
        if value is not None:
            return _parse_hstore(value.decode(encoding))

Some solution for the two to coexist would be good, for people who are using both Django and SQLAlchemy together.

One way might be to register the adapter only per connection/cursor, rather than globally (probably per cursor would be required for people using https://github.com/kennethreitz/django-postgrespool since the connections get shared).

@niwinz
Copy link
Member

niwinz commented May 20, 2014

Hi!

Registering in each connection seems to be much overhead for normal use case, in my opinion, and per connection registering works well with connection pools because it register hstore on each connection retrieval from pool.

(With https://github.com/djangonauts/djorm-ext-pool works well and it not requires special backend...)

@gthb
Copy link
Author

gthb commented May 22, 2014

“Registering in each connection seems to be much overhead” — did you mean “in each cursor”?

I agree (if that's what you meant) that per-connection makes more sense. The main thing is to get rid of globally=True, to allow django_hstore to coexist with SQLAlchemy.

@nemesifier
Copy link
Member

Another settings like: 02d398c ?

@niwinz
Copy link
Member

niwinz commented May 28, 2014

Yes @gthb! I was wrong!

Additional config with good entry on documentation for notify about it for any sqlalchemy users seems a good solution...

I'm currently very busy and I can't find time for it en almost three weeks :(

@nemesifier
Copy link
Member

I'm terribly busy too. @gthb pheraphs you could send a pull request with a patch similar to the one added by @niwibe: 02d398c

@DataMarket
Copy link

[Edit: This comment was actually from @gthb, mistakenly logged in as DataMarket.]

Me too : ) ... so I'll probably only do this if it becomes necessary to us to use HSTORE fields via Django. We don't need that (yet) so I just reported this and then backed out of using django-hstore for now.

@nemesifier
Copy link
Member

I was wondering... the settings instroduced in 02d398c is called HSTORE_GLOBAL_REGISTER, how would this setting be called?

@nemesifier
Copy link
Member

@nemesifier
Copy link
Member

discussion should continue on #50

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

No branches or pull requests

4 participants