Consistently handle `Promise` objects assigned to model fields.
|Reported by:||mrmachine||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, all Promise objects are passed to force_text() deep in ORM query code. Not only does this make it difficult or impossible for developers to prevent or alter this behaviour, but it is also wrong for non-text fields.
Field.get_prep_value() seems like a better place to handle Promise objects, and _proxy____cast() seems like a better way to do it than passing them through force_text(). All Field subclasses should call get_prep_value() on their super class to ensure they have a real value to work with.
This change would also facilitate the creation of custom fields like PickleField, which *can* store Promise objects, to override this behaviour.
Change History (4)
comment:1 Changed 3 years ago by mrmachine
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset