Currently, if we do:
tm.field = 'new field value'
tm.get_dirty_fields() #returns {'field': 'original field value'}
try:
with transaction.atomic():
tm.save()
raise Exception #force a rollback
except Exception:
pass
tm.get_dirty_fields() #returns {}
This behaviour is problematic, because field in-memory and database values are still different.
It seems like this will be tricky to solve.
We could have a property uncommitted_dirty_fields, which we could clear in an on_commit() signal, but I can't think of a way of setting dirty_fields = uncommitted_dirty_fields in the case of a rollback, since there is no on_rollback() signal.
edit: If we had some way of uniquely identifying the current transaction (I can't see one in current django api), we might be able set dirty_fields = uncommitted_dirty_fields inside get_dirty_fields() if transaction_at_time_of_last_save != current_transaction. Then there'd be some additional complexity from rollbacks inside nested transactions.
Currently, if we do:
This behaviour is problematic, because field in-memory and database values are still different.
It seems like this will be tricky to solve.
We could have a property
uncommitted_dirty_fields, which we could clear in anon_commit()signal, but I can't think of a way of settingdirty_fields = uncommitted_dirty_fieldsin the case of a rollback, since there is noon_rollback()signal.edit: If we had some way of uniquely identifying the current transaction (I can't see one in current django api), we might be able set
dirty_fields = uncommitted_dirty_fieldsinsideget_dirty_fields()iftransaction_at_time_of_last_save != current_transaction. Then there'd be some additional complexity from rollbacks inside nested transactions.