-
Notifications
You must be signed in to change notification settings - Fork 43
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
UnicodeDecodeError with UTF-8 queries #77
Comments
Thanks for the report! I don't think it's a personal issue, since it's Django that is creating the query. |
Django 1.10, though I can likely test this in some other versions as well. I’m fairly confident that just having |
Okay, the string causing issues is I think what we’re trying to do here is encode the string if it’s unicode, right? If so, just checking against So if that all sounds right, I think a two line pull request should fix our problems 😄 |
@karanlyons a PR that fixes an issue for you is more then welcome! Even better if it comes with tests, but if not I'll add them. I'm not sure yet which |
Sure, give me a little bit to write the tests and I’ll submit a PR we can look at. |
Alright, worryingly I’m having a hard time reproducing this in a test. The way this query is generated in my Django codebase is...questionable, but the error also happens with Django’s I’m not yet convinced that this isn’t actually my fault. |
Okay, so the issue turned out to be completely different than I thought: Django has a from __future__ import unicode_literals
from psycopg2.extras import DateTimeTZRange
from django.contrib.postgres.fields import DateTimeRangeField
class DateTimeRangeFieldWithBounds(DateTimeRangeField):
range_type = DateTimeTZRange
def __init__(self, *args, **kwargs):
self.default_bounds = kwargs.pop('default_bounds', '[)')
super(DateTimeRangeFieldWithBounds, self).__init__(*args, **kwargs)
...
Making the bounds kwarg And...I’m not sure where this leaves us. There definitely is a difference between what happens on CPython with psycopg2 and PyPy with psycopg2cffi, but I’m not totally certain where in that large variable surface the problem actually lies. |
Thanks for digging into it @karanlyons ! I think I finally understand the issue and what |
Yeah, I think just removing the |
@karanlyons hm, I just checked how
Can you check the arguments (and their types) that cause |
import psycopg2cffi
from psycopg2cffi.extras import DateTimeTZRange
from psycopg2cffi._impl.cursor import _combine_cmd_params
from datetime import datetime
conn = psycopg2cffi.connect("dbname='psycopg2_test' user='postgres' host='localhost'")
ascii_string = 'Test'
unicode_string = u'T\xe9st'
ascii_range = DateTimeTZRange(datetime.now(), datetime.now(), '[]')
unicode_range = DateTimeTZRange(datetime.now(), datetime.now(), u'[]')
# Works
_combine_cmd_params('%s', [ascii_string], conn)
_combine_cmd_params('%s', [unicode_string], conn)
_combine_cmd_params('%s', [ascii_range], conn)
_combine_cmd_params('%s', [unicode_range], conn)
_combine_cmd_params('%s %s', [ascii_string, ascii_range], conn)
_combine_cmd_params('%s %s', [unicode_string, ascii_range], conn)
_combine_cmd_params('%s %s', [ascii_range, unicode_range], conn)
# Fails
_combine_cmd_params('%s %s', [unicode_string, unicode_range], conn) Please tell me that last one fails for you too. This bug is either more complex than I thought or I’m insane, and I’m really hoping for the former. |
Yes, that does fail for me, thanks a lot for building a reproducer! Technically this is a bug in how Range objects are adapted, but the actual issue is deeper - |
This might be a personal issue, but it seems like there may still be some lingering encoding issues with this package. I see that there’s some work done in this function from #57, but it’s only under python 3.
I’m getting this error in 2.7 with
unicode_literals
.The text was updated successfully, but these errors were encountered: