Allow Model Cache Invalidation
|Reported by:||s.shanabrook@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I propose allowing a model instance to have its fields refetched from the database. For instance, it could work something like this.
>>> model = MyModel.objects.create() >>> model.field None >>> model.field = 'New Value' >>> model.field 'New Value' >>> model.invalidate() >>> model.field None
This is useful when testing a model. For instance, if I want to test a function that modifies a model, I currently have to re get the model from the database, before testing its fields, to make sure they have been saved.
model = MyModel.objects.create() model_modifier(model) assert model.field == 'New Value' model_non_caches = MyModel.objects.get(pk=model.pk) assert model.field == 'New Value'
Change History (4)
comment:1 Changed 2 years ago by jcatalan
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset