* Fixed an infinite recursion bug when deleting a model, that has a reverse relationship to a tracked model with SET_NULL on_delete
---------
Co-authored-by: Napat Ch <napat@thevcgroup.com>
This preserves the type of the wrapped descriptor (usually a field).
Maybe this is overkill, as `DescriptorWrapper` seems to only be used
as part of the `FieldTracker` implementation and is not documented
and barely tested. But technically, it is public API.
This catch was introduced in #367, but subsequent discussion
in #370, #381 and #382 suggests that it wasn't the proper solution.
Now that `AbstractModelTrackerTests` is re-enabled and passing,
it becomes clear that `AttributeError` is no longer raised during
unit testing when using a recent Django version. Therefore I think
it is safe to remove the `try`/`except`.
* add test for reproducing FieldTracker update_fields issue
FieldTracker does not see update_fields changed in tracked model.save() method
* Patch Model.save_base instead of save
This change allows proper capturing update_fields kwarg if is is changed in overridden save() method.
* Add some details about FieldTracker implementation
* Mention FieldTracker behavior change
* - add django 3.0 to the test matrix
- drop six
* add entry in CHANGES
* remove context kwarg
* fix test with DeferredAttribute
* rename StringyDescriptor's name to attname
* Fix flake8
* Drop support for Django 1.11 because the API are not compatibles anymore with Django 3.0
* Try to fix tests.
* Define model for the field mock.
* Simplifies the code.
* Properly mock the field.
* Typo
* Use the new API field name.
* Call it attname
* Grab the field instance from the model.
* Use postgres in travis tests.
* Django 2.0.1 minimum is needed.
* Update Changelog to tell about breaking Django 1.11.
* Update changelog to tell about Django 3.0 support.
* @natim review.
The complications are that when the attribute is set in Django 1.10,
it no longer counts as a deferred attribute, and it is not retrieved from the database.
Naively updating __set__ to retrieve the value if it is deferred leads to infinite
recursion because accessing the attribute involves loading data from the database
and trying to set the attribute based on that value. This commit introduces
a somewhat hacky flag that records whether we're already trying to set
the attribute further up in the call stack.
This commit adds a collection of wrapper classes for tracking fields
while still using custom descriptors that may be present. This fixes
a bug where deferring a model field with a custom descriptor meant
that the descriptor was overridden in all subsequent queries.
If a tracker is defined on an inherited model, where the parent has a ForeignKey,
the tracker will now correctly determine that the field_map takes `fk` -> `fk_id`
References #83.
Instead of patching the save method of a tracked model class, we can use
a signal handler on post_save, which means we can still pickle our model
class.
Note we can't just listen for the signal from the class we have, but
instead listen for all post_save signals. This means we actually install
a new signal handler for each tracked model class, which fires on all
model save occurrences (and returns immediately if this handler doesn't care).
We probably could improve this to have a registry of tracked models, or
something, that allows us to just install one signal handler, and filter
according to membership.