printing a 'compiler' results in AttributeError: 'PGCompiler_psycopg2' object has no attribute 'string'

110 views
Skip to first unread message

Jonathon Nelson

unread,
Jun 30, 2015, 6:32:07 PM6/30/15
to sqlal...@googlegroups.com
When trying to debug something, I tried to acquire the string representation of a 'compiler' object.
I got this error:

  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 218, in __str__
    return self.string or ''
AttributeError: 'PGCompiler_psycopg2' object has no attribute 'string'


It would appear that trying to acquire the string representation of the object (before instantiation) fails.
:-(


Mike Bayer

unread,
Jun 30, 2015, 7:18:20 PM6/30/15
to sqlal...@googlegroups.com
how are you getting this Compiler object?  the .string element is created within the constructor.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Jonathon Nelson

unread,
Jun 30, 2015, 7:21:42 PM6/30/15
to sqlal...@googlegroups.com
On Tue, Jun 30, 2015 at 6:18 PM, Mike Bayer <mik...@zzzcomputing.com> wrote:
how are you getting this Compiler object?  the .string element is created within the constructor.

It was actually as a result of trying to figure out how to use the code you gave me for the psycopg2 percentile escaping thing:


from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import TextClause

@compiles(TextClause, "postgresql")
def _reverse_escaping(element, compiler, **kw):
    # I PUT THE stringification of 'compiler' here
    text = compiler.process_text(element, **kw) # should be .post_process_text?
    text = text.replace("%%", "%")
    return text


 

--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/xXYGOZoCg40/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.



--
Jon Nelson
Dyn / Senior Software Engineer
p. +1 (603) 263-8029

Mike Bayer

unread,
Jun 30, 2015, 8:02:06 PM6/30/15
to sqlal...@googlegroups.com


On 6/30/15 7:21 PM, Jonathon Nelson wrote:


On Tue, Jun 30, 2015 at 6:18 PM, Mike Bayer <mik...@zzzcomputing.com> wrote:
how are you getting this Compiler object?  the .string element is created within the constructor.

It was actually as a result of trying to figure out how to use the code you gave me for the psycopg2 percentile escaping thing:

Well Compiler likes to return the SQL from __str__(), so if the SQL isn't there, i suppose it could return some generic thing, but then again __repr__() might be better to call in any case.
Reply all
Reply to author
Forward
0 new messages