PickleType can't be indexed in MySQL

Issue #2420 resolved
Former user created an issue

This is a pretty specific one. When using the PickleType in MySQL in an indexed column, table creation fails. This is because PickleType doesn't support a length parameter, and MySQL doesn't allow a table field to be indexed without defining a length.

My workaround was this:

class PickleWithLengthType (PickleType):
    def __init__(self, protocol=pickle.HIGHEST_PROTOCOL,
                    pickler=None, mutable=False, comparator=None, length=None):
        self.length = length
        super(PickleWithLengthType, self).__init__()

I'm attaching a proposed patch as well, it's fairly straightforward.

Comments (5)

  1. Former user Account Deleted

    I forgot to add something. In my workaround I also used this:

    @compiles(LargeBinary, "mysql")
    def compile_LargeBinary_mysql(type_, compiler, **kw):
        return "BLOB"
    

    I would have thought LargeBinary produced BLOB columns on MySQL, but my code seems to fail if I don't override the type compilation like this. :(

  2. Former user Account Deleted

    Argh, my bad! It seems SQLAlchemy is raising an exception even though the table is created. I only thought it was working because the table was already there and create_all() was doing nothing! :P

    I don't know yet how to make this work then, please ignore my failed patch...

  3. Log in to comment