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

LoggingConnection fails with "can't concat bytes to str" error in Python 3 #483

Closed
VladV opened this Issue Oct 28, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@VladV
Copy link

VladV commented Oct 28, 2016

I initialize LoggingConnection as following: connection.initialize(open('sql.log', a)).
When executing a query, the logging fails here, since msg is bytes:

    def _logtofile(self, msg, curs):
        msg = self.filter(msg, curs)
        if msg: self._logobj.write(msg + _os.linesep)

Here query is str, but self.query is bytes:

    def execute(self, query, vars=None):
        try:
            return super(LoggingCursor, self).execute(query, vars)
        finally:
            self.connection.log(self.query, self)
@dvarrazzo

This comment has been minimized.

Copy link
Member

dvarrazzo commented Oct 31, 2016

mmm, yes, I guess that cursor was meant more as an example than as something serious to work with. However it's in the lib so we'll have to maintain it. Thank you for the report.

I guess that's Python 3.x, right?

@VladV

This comment has been minimized.

Copy link

VladV commented Oct 31, 2016

Sure, Python 3.5 that is.

It's obviously easy to fix the cursor. However, there probably are some inconsistencies in the code that result in query being bytes or string in different places under Python 3. I'm not familiar with the library code enough to suggest whether and how in should be fixed.

@dvarrazzo

This comment has been minimized.

Copy link
Member

dvarrazzo commented Oct 31, 2016

Query is always a binary, encoded in the connection encoding. The most important parts of the adapter are well tested and the string types tracked correctly. This object hasn't received as much love as others.

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