There are small typos in:
- docs/managers.rst
- model_utils/managers.py
- tests/test_models/test_timestamped_model.py
Fixes:
- Should read `subclasses` rather than `subclasess`.
- Should read `queryset` rather than `querset`.
- Should read `permissible` rather than `permissable`.
- Should read `modified` rather than `modifed`.
- Should read `heterogeneous` rather than `heterogenous`.
Signed-off-by: Tim Gates <tim.gates@iress.com>
When calling `select_related()` with an empty list of arguments [1], Django will
try to prefetch some data by doing some first level joints with the related
classes.
This can lead to obvious negative performance impact, but this also breaks some
workarounds for having inheritance for foreign keys [2], as those solutions rely
on lazy evaluation of the related object.
[1]: a4e6030904/django/db/models/query.py (L1051)
Only passing an explicit `None` to `select_related` will disable the magic.
[2]: https://github.com/jazzband/django-model-utils/issues/11
As examples, here are the generated SQL requests in
InheritanceManagerRelatedTests.test_get_method_with_select_subclasses_check_for_useless_join:
* without this fix, without adding `.select_related(None)`
```sql
SELECT
"tests_inheritancemanagertestparent"."id",
"tests_inheritancemanagertestparent"."non_related_field_using_descriptor",
"tests_inheritancemanagertestparent"."related_id",
"tests_inheritancemanagertestparent"."normal_field",
"tests_inheritancemanagertestparent"."related_self_id",
"tests_inheritancemanagertestchild4"."other_onetoone_id",
"tests_inheritancemanagertestchild4"."parent_ptr_id", T3."id",
T3."non_related_field_using_descriptor", T3."related_id", T3."normal_field",
T3."related_self_id"
FROM
"tests_inheritancemanagertestchild4"
INNER JOIN
"tests_inheritancemanagertestparent" ON
("tests_inheritancemanagertestchild4"."parent_ptr_id" = "tests_inheritancemanagertestparent"."id")
INNER JOIN
"tests_inheritancemanagertestparent" T3 ON
("tests_inheritancemanagertestchild4"."other_onetoone_id" = T3."id")
WHERE
"tests_inheritancemanagertestchild4"."parent_ptr_id" = 191
```
* with either the fix, or by adding `.select_related(None)` after `.select_subclasses()`
```sql
SELECT
"tests_inheritancemanagertestparent"."id",
"tests_inheritancemanagertestparent"."non_related_field_using_descriptor",
"tests_inheritancemanagertestparent"."related_id",
"tests_inheritancemanagertestparent"."normal_field",
"tests_inheritancemanagertestparent"."related_self_id",
"tests_inheritancemanagertestchild4"."other_onetoone_id",
"tests_inheritancemanagertestchild4"."parent_ptr_id"
FROM
"tests_inheritancemanagertestchild4"
INNER JOIN
"tests_inheritancemanagertestparent" ON
("tests_inheritancemanagertestchild4"."parent_ptr_id" = "tests_inheritancemanagertestparent"."id")
WHERE
"tests_inheritancemanagertestchild4"."parent_ptr_id" = 191
```
* Overriding TimeStampedModel's save() method
to update modified field automatically when update_fields argument is used but modified was not given as a parameter.
* fixed a small error in logic
* added tests for new functionality
* 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.
* ✅ Ensure TimeStampedModel modified equals created on initial creation.
Add logic to AutoLastModifiedField which checks to see if the associated created field of the correct cField class type is also present. If the instance has not yet been saved (missing a pk), then set the value to modified to be equal to created.
Fixes#247📚 Update changes and authors list related to changes.
* 🚑 Set TimeStampedModel modified to be equal to created during first save.
If instance does not yet have a pk, before defaulting the last modified to the current time, iterate over the the fields of the model, and instead use whatever value is found in the first occurance of the AutoCreatedField.
Fixes#247
* Move changelog up to unreleased section.
* Add the join manager + tests
* Documentation for join manager
* Use order_by for consistent tests
* Use postgres instead sqlite for tests for better reliability
* Fix coverage
* Drop django 1.8
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.