This PR improves a DataBaseModel's ability to handle model definition moves within a project. Because pickle expects the same module/attribute(BaseModel or other class) to exist when performing loads from a bytestring, movements such as complete DataBaseModel or attribute definitions could result in AttributeError during migration.
New Solution
If an AttributeError or ModuleNotFound error is detected during loads (deserialization), pydbantic will add a dummy module matching the missing module(if relevant), or add a generic BaseModel matching the missing attribute name to expected Module defition, which allows deserialization to complete, and thus migrations. It is expected that attribute location definition changes will trigger a migration.
Updated Tests
Previous tests covered partial handling of only AttributeError correction, but are now updated to include ModuleNotFoundError
New / Adjust in, not_in attribute methods
Added DataBaseModelAttribute method .inside() and .not_inside() for a more natural way of filtering via .filter() with a in or not in list of items condition, eventually replacing .matches & not_matches
De-Serialization Enhancements
This PR improves a
DataBaseModel
's ability to handle model definition moves within a project. Becausepickle
expects the same module/attribute(BaseModel or other class) to exist when performingloads
from a bytestring, movements such as completeDataBaseModel
or attribute definitions could result inAttributeError
during migration.New Solution
If an
AttributeError
orModuleNotFound
error is detected duringloads
(deserialization), pydbantic will add a dummy module matching the missing module(if relevant), or add a genericBaseModel
matching the missing attribute name to expected Module defition, which allowsdeserialization
to complete, and thus migrations. It is expected that attribute location definition changes will trigger a migration.Updated Tests
Previous tests covered partial handling of only
AttributeError
correction, but are now updated to includeModuleNotFoundError
New / Adjust
in
,not_in
attribute methodsAdded
DataBaseModelAttribute
method.inside()
and.not_inside()
for a more natural way of filtering via.filter()
with ain
ornot in
list of items condition, eventually replacing.matches
¬_matches
Example