Commit graph

71 commits

Author SHA1 Message Date
Maarten ter Huurne
00937608fa Add type argument to DescriptorWrapper
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.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
f4653f08e5 Preserve tracked function's return type in FieldTracker 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
56ea527286 Annotate the tracker module 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
0043fedf46 Enable postponed evaluation of annotations for all source modules
This allows using the latest annotation syntax supported by the type
checker regardless of the runtime Python version.
2024-06-13 12:02:05 +02:00
Maarten ter Huurne
14cf1b0d40 Remove catching of AttributeError in DescriptorWrapper
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`.
2024-06-12 16:55:45 +02:00
Jelmer
7b8a58b871
Merge pull request #580 from joecox/remove-dead-tracker-code
Remove dead `init_deferred_fields` method
2024-03-21 08:47:53 +01:00
meanmail
5663374890 Don't use post_init signal for initialize tracker 2024-03-11 17:50:12 +01:00
Joe Cox
b2a10bd96c remove dead init_deferred_fields method 2023-09-11 16:25:16 -07:00
joeriddles
a0624f1492 For error on prefetch_related for tracked field 2023-01-26 13:17:49 -08:00
Matthieu Rigal
6d4112e8ce
Fix performance regression: avoid pickling the whole instance when deepcopying fields on Django 3.1+ (#500)
* test: Add failing test for #gh-498

* fix: Fix performance regression on FileTracker for FileField on Django 3.1+
2021-10-09 21:30:12 +06:00
Sergey Tikhonov
79a7793dc5
#491 Context manager for resetting fields (#494)
* Add tracker context manager and decorator

* Handle auto-field warning in tests

* Use tracker context in monkey-patched methods

* Test delaying set_saved_fields call with context manager

* Docs for tracker context

* Describe FieldsContext context manager in changes

* Fix unused import

* #494 add breaking changes note on 4.1.1 release for #404

* #494 fix typo

* #494 add docstring for FieldsContext

* #494 move breaking changes from 4.1.1 to 4.1.0

* #494 fix typo and add some more docstrings
2021-10-08 15:09:20 +06:00
Hasan Ramezani
92ff6b927f Remove codes related to old versions of Django. 2020-11-28 21:46:25 +01:00
Ben Steinberg
eba26d6bd4 Fix typo 2020-10-29 09:11:30 -04:00
skazancev
bf4b65a437 removed model from DeferredAttributeTracker 2020-05-28 22:40:13 +06:00
Sergey Tikhonov
1386c379b7 FieldTracker should patch save_base instead of save (#404)
* 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
2019-12-15 22:43:58 +06:00
Sergey Tikhonov
d756a4a8ce patch Model.refresh_from_db in FieldTracker (#403)
* patch Model.refresh_from_db in FieldTracker

* add info about refresh_from_db patching to CHANGES.rst
2019-12-15 20:28:15 +06:00
Misha K
5aa40c66be Add django 3.0 to the test matrix and drop six (#395)
*  - 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.
2019-12-09 19:37:16 +06:00
Adam Dobrawy
ffa1a85dc7 Modernize Python syntax, add Python 3.8 (#398)
* Modernize Python syntax, add Python 3.8

* Update Python version & dist in TravisCI

* Add postgresql as addon

* Switch to psycopg2-binary

* Drop django.utils.six
2019-11-14 22:50:04 +06:00
Hasan Ramezani
aa94194dbc Drop Python 2 support. (#394) 2019-09-30 14:08:52 +06:00
Rémy HUBSCHER
e6c7b567d1
Remove unsupported django version hacks. 2019-08-21 11:02:23 +02:00
Jack Cushman
f2e97e4141 Move patch_save to finalize_class so it works on models with save() methods 2019-04-25 17:50:08 -04:00
Nick Sandford
d557c42533 Catch deferred attribute exception (#367) 2019-03-29 12:46:40 +06:00
Sergey Tikhonov
6b88c888d3 fix model.save patched in FieldTracker (#353)
* fix model.save patched in FieldTracker

* add test for save call with args

* update changes
2018-12-10 21:35:26 +06:00
tumb1er
ba83be0b43 fix #330 patch MyModel.save instead of MyModel().save 2018-11-20 18:32:09 +03:00
Lucas Wiman
da65d0be32 Fix E30X too-few line spacing errors. 2018-07-02 12:20:38 -07:00
Lucas Wiman
7d6b45f0c1 Increase coverage: verify that accessing the descriptor from the class yields the descriptor object. 2018-06-28 17:04:57 -07:00
Lucas Wiman
ca2fbb4ccd Fix coverage for a codepath only executed in <1.10 environments. 2018-06-28 16:59:30 -07:00
Lucas Wiman
59347ef36f Correctly clean up recursion sentinel value. 2018-06-28 13:52:52 -07:00
Lucas Wiman
15f9393bb2 Handle API change in DeferredAttribute descriptor in django-trunk.
This should maintain compatibility with the next version of django.
2018-06-28 13:16:33 -07:00
Lucas Wiman
a84c3afddd Fix behavior of .previous() in Django 1.10+.
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.
2018-06-28 13:15:56 -07:00
Lucas Wiman
5d410e9ccc Fix test failures from merge. 2018-06-28 11:29:44 -07:00
Lucas Wiman
98a1366608 Merge branch 'defer-has-changed' into django-1.11-compatibility 2018-06-21 12:52:33 -07:00
Lucas Wiman
90ed7fc905 Improve coverage. 2018-06-21 12:41:42 -07:00
Lucas Wiman
80b099f129 Do not override custom descriptors when present.
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.
2018-06-21 12:41:42 -07:00
Lucas Wiman
be52bc9290 Add failing test for deferred attributes. 2018-06-21 12:41:42 -07:00
Lucas Wiman
0fc0b44c95 Remove version checks for django<1.8.
Support for older versions of django was dropped in 3.0.0.
2018-06-21 12:41:42 -07:00
Jack Cushman
d34043fd25 Avoid fetching deferred fields in has_changed 2018-02-10 10:53:36 -05:00
Alexey Evseev
9ee6065f81 Support Django 1.10 deferred FileField with FieldTracker 2016-09-08 18:00:48 +03:00
Jarek Glowacki
bbc076429a Nicer solution 2016-08-17 11:48:27 +10:00
Jarek Glowacki
922c49770e Django 1.10 support for FieldTracker 2016-08-15 12:24:07 +10:00
Roman
7ec978e1d8 1.10 fix 2016-05-27 20:32:16 +00:00
Mike Bryant
ff3f8e5546 Use all the fields to determine _id variants. Fixes #214
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`
2016-03-31 15:45:19 +01:00
bboogaard
041ef6b838 Keep track of deferred fields on model instance
Instead of on FieldInstanceTracker instance

Signed-off-by: bboogaard <b.boogaard@auto-interactive.nl>
2014-08-19 10:29:03 +02:00
Carl Meyer
a127e32217 Revert "Use a signal handler instead of patching save."
This reverts commit 3496fe4291.
2014-07-31 18:08:24 -06:00
Matthew Schinckel
3496fe4291 Use a signal handler instead of patching save.
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.
2014-05-12 14:32:59 +09:30
Michael van Tellingen
2bcddd5be9 Add fix for Django 1.4 2014-03-01 14:24:25 +01:00
Michael van Tellingen
6ffae1ad8f Add support for deferred fields in the FieldTracker 2014-03-01 13:34:17 +01:00
Trey Hunner
e1faec7577 Merge pull request #73 from silonov/json_fields_support
Json fields support
2013-08-17 01:46:31 -07:00
Trey Hunner
2679f6114b Merge branch 'silonov-json_fields_support'
Conflicts:
	CHANGES.rst
	model_utils/tests/tests.py
2013-08-17 01:40:09 -07:00
Mikhail Silonov
ef510d53dd Removed reinvented wheel 2013-08-12 13:22:34 +04:00