The Unicode datatype will emit a warning if you pass it a bytestring. you can
use that instead of String, or use a datatype with your own assertions based on
https://docs.sqlalchemy.org/en/14/core/custom_types.html#coercing-encoded-strings-to-unicode
On Thu, Jul 29, 2021, at 5:17 PM, 'Jonathan Vanasco' via sqlalchemy wrote:
> I am finally at the tail end of migrating my largest (and hopefully last)
> Python2 application to Python3.
>
> An issue that has popped up a lot during this transition, is when a py3
> bytestring gets submitted into SqlAlchemy.
>
> When that happens, it looks like SqlAlchemy just passes the value into
> psycopg2, which wraps it in an object, and I get a psycopg exception that
> bubbles up to SqlAlchemy:
>
> > sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction)
> > operator does not exist: character varying = bytea
> > LINE 3: WHERE foo = '\x626337323133...
> > HINT: No operator matches the given name and argument type(s). You might
> > need to add explicit type casts.
> > ....
> > WHERE foo = %(foo)s
> > LIMIT %(param_1)s]
> > [parameters: {'foo': <psycopg2.extensions.Binary object at 0x10fe99060>,
> > 'param_1': 1}]
> > (Background on this error at: http://sqlalche.me/e/13/f405)
>
> Is there an easy way to catch this in SQLAlchemy *before* sending this to the
> driver and executing it on the server? I'd like to ensure I'm catching
> everything I should, and nothing is working just by-chance.
>
>
>
>
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/f70bf020-d120-46fb-96d1-d5509ff9b3c3n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/f70bf020-d120-46fb-96d1-d5509ff9b3c3n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/a1752866-74c3-4c18-9e2c-47a98d70858d%40www.fastmail.com.