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

pg8000 in py2 eventually calls text_out with a str object, causing an unnecessary failure #93

Closed
infinity0 opened this issue Jan 24, 2016 · 3 comments

Comments

@infinity0
Copy link

Hi, text_out is causing errors with Apple's CalendarServer. Details of the issue here.

TL;DR is that I can fix the immediate problem by applying this patch:

diff --git a/pg8000/core.py b/pg8000/core.py
index 246e0b6..14093cc 100644
--- a/pg8000/core.py
+++ b/pg8000/core.py
@@ -1350,6 +1350,7 @@ class Connection(object):
         self.ParameterStatusReceived += self.handle_PARAMETER_STATUS

         def text_out(v):
+            if not isinstance(v, text_type): return v
             return v.encode(self._client_encoding)

         def time_out(v):

However I'm not sure if this is best for pg8000 in general. Please let me know what you think, and also if we need to patch CalendarServer in some other way as well.

@tlocke
Copy link
Collaborator

tlocke commented Feb 7, 2016

The short answer is that under Python 2 it's probably a good idea to send strings as unicode() objects, rather than str() objects.

Having said that, I think that pg8000 is doing the wrong thing when running under Python 2. If it receives a str() it should really send it unmodified (ie. use the bytea_send() method). I'll go ahead and put something up and see what people think.

@tlocke
Copy link
Collaborator

tlocke commented Feb 21, 2016

For sending a str under Python 2 we used to do an encode() on it, then
send it. The problem was this first does an implicit decode() with the
default encoding (usually ascii) and the decode would fail on anything
that wasn't valid ascii encoded bytes. To solve that we now say that
under Python 2, str types are sent unmodified. For users of the library
it's safest to send strings using the unicode type. I've pushed this change to the main rep.

@tlocke
Copy link
Collaborator

tlocke commented Feb 27, 2016

I think this issue is addressed in release 1.10.4, so I'll close this issue.

@tlocke tlocke closed this as completed Feb 27, 2016
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

2 participants