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

HStoreDict does not convert long integers to strings. #60

Closed
mattiaslinnap opened this issue Aug 21, 2014 · 3 comments
Closed

HStoreDict does not convert long integers to strings. #60

mattiaslinnap opened this issue Aug 21, 2014 · 3 comments
Labels

Comments

@mattiaslinnap
Copy link

Python "long" integers are not converted to strings by HStoreDict.ensure_acceptable_value(). Usual integers are silently promoted to infinite-sized long integers by Python, and surprisingly long is not a subclass of int.

>>> from django_hstore.dict import HStoreDict as HSD
>>> HSD({'a': 123})
{'a': u'123'}
>>> HSD({'a': 12345678901234567890})
{'a': 12345678901234567890L}
>>> type(HSD({'a': 12345678901234567890})['a'])
<type 'long'>
>>> isinstance(1, int)
True
>>> isinstance(12345678901234567890, int)
False
>>> isinstance(12345678901234567890, long)
True

This can eventually result in a mixed string and integer PostgreSQL array being passed to the hstore() constructor, and PostgreSQL complaining about strings not being integers.

A proposed fix is to add "long" to the list of types in https://github.com/djangonauts/django-hstore/blob/1.3.0/django_hstore/dict.py#L123

@mattiaslinnap
Copy link
Author

Also, I haven't looked much into the new Schema Mode yet, but isn't the if statement at https://github.com/djangonauts/django-hstore/blob/1.3.0/django_hstore/dict.py#L120 the wrong way around? Isn't converting everything to a string the right thing to do exactly when there is no schema?

@nemesifier nemesifier added the bug label Aug 25, 2014
@nemesifier
Copy link
Member

@mattiaslinnap there's a whole block of comments, if you read it you will understand why it is coded that way.
I'll check @Naddiseo's patch soon.

nemesifier added a commit that referenced this issue Aug 25, 2014
nemesifier pushed a commit that referenced this issue Aug 25, 2014
Use `six.integer_types`
@nemesifier
Copy link
Member

should be fixed, let us know.

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

No branches or pull requests

2 participants