I have a custom field that stores the import path to a Python class. The db_value takes the class object and coverts it to the import path string and the python_value takes the string and imports the object giving me back the class. However, as of peewee 3.13.2 this no longer works and instead gives me peewee.InternalError: (1054, "Unknown column 't1' in 'field list'") when I try to save.
Field:
class PythonObjectField(CharField):
"""
A custom class for storing a Python object as a reference.
"""
def db_value(self, value):
if value is None:
return None
elif isinstance(value, str):
return value
return get_object_path(value)
def python_value(self, value):
if value is None:
return None
return import_object(value)
The usage would be Model.field = SomeOtherModel
When debugging this I found that this affects my Model derived classes but not a simple one that only extends object. Additionally, I found that db_value is never called.
It isn't calling db_value() because peewee sees that you're using a model class as a value, which is a recognized AST type. The issue that originated this fix is #2131.
Thanks for reporting, this is fixed in master now.
Thank you! I just wanted to drop a note saying how much I've enjoyed using peewee and how appreciative I've been have your responsiveness to issues.
Most helpful comment
Thank you! I just wanted to drop a note saying how much I've enjoyed using peewee and how appreciative I've been have your responsiveness to issues.