Column defaults don't get passed through custom type's convert_bind_param

Issue #756 resolved
Former user created an issue

The following works in 0.3.10, but not in 0.4beta3. In 0.4beta3, I get the following error:

sqlalchemy.exceptions.InterfaceError: (InterfaceError) Error binding parameter 1 - probably unsupported type. u'INSERT INTO jsontest (name, test) VALUES (?, ?)' [[]('foo',)]



#!python
import simplejson, copy

class JSONCol(types.MutableType, types.TypeDecorator):
    impl = types.Unicode
    def convert_bind_param(self, value, engine):
        if value is None:
            return None
        return simplejson.dumps(value)

    def convert_result_value(self, value, engine):
        if value is None:
            return None
        return simplejson.loads(value)

    def copy_value(self, value):
        return copy.deepcopy(value)

if __name__ == "__main__":
    from sqlalchemy import *
    metadata = MetaData("sqlite:///")
    t = Table("jsontest", metadata,
            Column("id", Integer, primary_key = True),
            Column("name", String),
            Column("test", JSONCol, nullable = False, default = [           )

    metadata.create_all()

    t.insert().execute(name = "foo")
    t.insert().execute(name = "bar", test = [1,2,3](]),
))

    print t.select().execute().fetchall()

Comments (2)

  1. Mike Bayer repo owner

    the issue reproduces with 0.4beta3 but not in the latest trunk. will be releasing beta4 shortly.

  2. Mike Bayer repo owner

    oh in fact I know exactly why you're getting this error - the convert_bind_param and convert_result_value methods were removed as of beta3. So the issue is not defaults, its your methods weren't being called at all. Since then, ive restored a "compatibility" layer which checks for the presence of these methods and wires them in, and we have test coverage for that.

  3. Log in to comment