I have a complex object with multiple nested dicts and lists which I’d like to save to the database.
I’ve tried pickling the object which seems to work but then get an error when setting/updating the database column:
anvil.server.SerializationError: Cannot serialize arguments to function. Cannot serialize <class ‘bytes’> object at msg[‘kwargs’][‘tl_factory_object_media’]
I’ve tried using both a simple object data type column as well as media. I suspect the object is either too big or not fully pickled, if that is possible, maybe due to the nested structure.
Any suggestions and/or clarification would be appreciated.
I’m also considering trying to write it out to a file and storing the file as media.
Do you have a clone link you could share that is a minimal example of the problem you’re facing?
I presume this is all server-side stuff?
For simple object - I think better would be to do a json.dumps because a simple object is really a json object which is text-based whereas a pickle object probably would not be json enough for simple object table storage hence the serialization error…
Depending on how deep the rabbit hole goes you can store media objects in media columns…
Is this a Media column?
If this is the case, then you need to create a BlobMedia, not a json or a pickled string.
If you want to store a json structure you can create a Simple Object column, so you don’t even need to convert it to json.
Yes, I now see that file should be a media type. This was a second column I was trying as I was thinking of trying to write to a file and storing to this column.
The original column is a simple object and I was getting the same error–I’ll try again.