Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread 'Jonathan Vanasco' via sqlalchemy
The second option looks perfect. Will try it! Thank you so much, Simon! On Friday, July 30, 2021 at 1:32:42 PM UTC-4 Simon King wrote: > I can think of a couple of options: > > 1. Create a TypeDecorator for String and Text columns that raises an > error if it sees a bytestring. This will only

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread Simon King
I can think of a couple of options: 1. Create a TypeDecorator for String and Text columns that raises an error if it sees a bytestring. This will only flag the error when the session is flushed. 2. Listen for mapper_configured events, iterate over the mapper properties and add an

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread 'Jonathan Vanasco' via sqlalchemy
Mike, thanks for replying but go back to vacation. Anyone else: I am thinking more about an event that can be used to catch, perhaps log, all bytes that go in. I only use a few column classes that expect bytestrings, but many that do not. I've gotten every known bug so far, but I'd like to

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-29 Thread Mike Bayer
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,

[sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-29 Thread 'Jonathan Vanasco' via sqlalchemy
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