ISQLQuote vs. str subclass
ISQLQuote vs. str subclass
От:
Jonathan Rogers <jrogers@socialserve.com>
Дата:
I have a custom subclass of str called LiteralValue, the purpose of which is to represent a string which should be passed to Postgres unmodified. Its getquoted() method simply returns itself. This type worked as intended with psycopg2 up to version 2.2.x. However, versions of psycopg2 2.3 and newer no longer call getquoted() on objects of type LiteralValue. Is this an expected change in behavior? -- Jonathan Ross Rogers
Re: ISQLQuote vs. str subclass
От:
Daniele Varrazzo <daniele.varrazzo@gmail.com>
Дата:
On Fri, Jul 31, 2015 at 3:57 PM, Jonathan Rogers wrote: > I have a custom subclass of str called LiteralValue, the purpose of > which is to represent a string which should be passed to Postgres > unmodified. Its getquoted() method simply returns itself. This type > worked as intended with psycopg2 up to version 2.2.x. However, versions > of psycopg2 2.3 and newer no longer call getquoted() on objects of type > LiteralValue. Is this an expected change in behavior? I don't think so, not intentionally at least. If the class is self-adapting, does it expose a __conform__() method? If it has an associated wrapper is it registered? http://initd.org/psycopg/docs/advanced.html#adapting-new-python-types-to-sql-syntax If you post the implementation I can try and take a look. -- Daniele
Re: ISQLQuote vs. str subclass
On 07/31/2015 12:08 PM, Daniele Varrazzo wrote: > On Fri, Jul 31, 2015 at 3:57 PM, Jonathan Rogers > wrote: >> I have a custom subclass of str called LiteralValue, the purpose of >> which is to represent a string which should be passed to Postgres >> unmodified. Its getquoted() method simply returns itself. This type >> worked as intended with psycopg2 up to version 2.2.x. However, versions >> of psycopg2 2.3 and newer no longer call getquoted() on objects of type >> LiteralValue. Is this an expected change in behavior? > > I don't think so, not intentionally at least. If the class is > self-adapting, does it expose a __conform__() method? If it has an > associated wrapper is it registered? > > http://initd.org/psycopg/docs/advanced.html#adapting-new-python-types-to-sql-syntax > > If you post the implementation I can try and take a look. Here's a sample script which demonstrates the difference in behavior. Using psycopg2 2.2.1, it prints four lines of "select 5". Using psycopg2 2.3, the line using a LiteralValue is "select '5'". -- Jonathan Ross Rogers