we might have to implement the _binary thing on our end.   especially if
all the MySQL drivers have the same issue, plus Django went ahead and did
the _binary thing already making it less likely the drivers will.

that said, here's how to get _binary for now, this might be what we add on
our end:

from sqlalchemy import Column, Integer, create_engine, TypeDecorator
from sqlalchemy.sql import operators
from sqlalchemy.orm import Session
from sqlalchemy.sql.expression import UnaryExpression
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects import mysql

Base = declarative_base()


class SafeBlob(TypeDecorator):
    impl = mysql.BLOB

    def bind_expression(self, bindvalue):
        return UnaryExpression(
            bindvalue, operator=operators.custom_op("_binary")
        )


class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)
    city = Column(SafeBlob())

e = create_engine("mysql://scott:tiger@mysql57/test?charset=utf8mb4",
echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)

data =
b'z\xf9\x87jS?\xd4i\xa5\xa3\r\xa7\x1e\xed\x16\xe0\xb5\x05R\xa4\xec\x16\x8f\x06\xb5\xea+\xaf<\x00\\\x94I9A\xe0\x82\xa7\x13\x0c\x8c'
s = Session(e)
s.add(A(city=data))
s.commit()






On Sun, Mar 11, 2018 at 9:25 PM, <[email protected]> wrote:

> Well that’s good news then, thanks Mike 🤓
>
>
> On Monday, March 12, 2018 at 11:08:28 AM UTC+10, Mike Bayer wrote:
>>
>> the issue is Python 3 only and reproduces with PyMySQL 0.8.0 and not
>> with 0.7.1.    Hopefully this is a PyMySQL bug that can be resolved
>> quickly (note I might recall seeing this recently but could not find
>> any discussion about it).   Posted up as
>> https://github.com/PyMySQL/PyMySQL/issues/644 .
>>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to