TypeDecorator subclass trying to compare against NO_VALUE

184 views Asked by At

I have a subclass myTypeSA of sqlalchemy.types.TypeDecorator that defines process_bind_param and process_result_value as follows to allow persistance of myType instances to the database:

    class myTypeSA(types.TypeDecorator):
        """ Decorate String type to translate myType instance into String in the database"""
        impl = types.String(15)

        def process_bind_param(self, value, dialect):
            if value is None:
                return None
            assert type(value) == myType
            return value.as_str()

        def process_result_value(self, value, dialect):
            if value is None:
                return None
            return myType.from_str(value)

At some point in a commit, sqlalchemy seems to try to see if an object has changed, and calls TypeDecorator.compare_values which defaults to sa.String compare_values , ie TypeEngine.compare_values. This is really just x == y , which asserts in my case because x is an instance of myType and y is a sqlalchemy string : NO_VALUE .

I'm tempted to override directly TypeDecorator.compare_values to fix this issue but I wonder if I missed something and should override coerce_compared_value or process_literal_param ; the comments detailing when those methods are used are not very clear to me. How should that comparison against NO_VALUE have been handled?

Thanks

0

There are 0 answers