python-diskcache icon indicating copy to clipboard operation
python-diskcache copied to clipboard

Custom serializer cannot return "None"

Open rommeswi opened this issue 1 year ago • 0 comments

I tried to write a custom serializer that does not serialize functions. Assuming returning None would avoid serialization, I tried:

def custom_serializer(key, value):
    if callable(value):
        # If value is a function, return None to exclude it from serialization
        return None
    else:
        # Serialize non-function values using the default pickle serializer
        return pickle.dumps(value)

However, this does not work due to an sql error sqlite3.ProgrammingError: Error binding parameter 2: type 'function' is not supported. The above serializeronly works only if the serializer returns not None.

I am not sure if this is an actual issue or whether I am using the wrong appoarch?

rommeswi avatar May 15 '24 08:05 rommeswi