Commit graph

103 commits

Author SHA1 Message Date
Maarten ter Huurne
6c39b58cb4 Remove FeaturedManager and related obsolete test model code
The code under test was removed in 6ae66e01, but some of the test code
remained.
2024-03-22 18:43:45 +01:00
Jelmer
6e722b51b0
Merge pull request #596 from ProtixIT/status-test-model-naming
Resolve name clash among test models
2024-03-22 18:00:40 +01:00
Jelmer
aaf93c9d40
Merge pull request #595 from ProtixIT/skip-reason
Pass reason to `@skip` decorator
2024-03-22 18:00:03 +01:00
Jelmer
281c52013e
Merge pull request #594 from ProtixIT/joinmanager
Remove redundant definition of `JoinManager` from tests
2024-03-22 17:58:14 +01:00
Maarten ter Huurne
ed4f04f282 Resolve name clash among test models
There were two classes named `StatusCustomManager`: the first is an
actual manager, the second a status model that uses a custom manager.
The latter is renamed to `CustomManagerStatusModel` in this commit.
2024-03-22 17:32:51 +01:00
Maarten ter Huurne
ab8a8ae53a Pass reason to @skip decorator
The decorator works without an argument as well, but that is an
undocumented feature of `unittest.skip()` that is not understood
by mypy and pytest.

In the case of pytest, it ignored the decorated class during test
collection, instead of collecting it and marking it as skipped.
2024-03-22 16:58:09 +01:00
Maarten ter Huurne
b7677161cb Remove redundant definition of JoinManager from tests
The `JoinManager` class already exists in `model_utils.managers`,
with the exact same definition.
2024-03-22 16:29:37 +01:00
Jelmer Draaijer
1979d4796f USE_TZ = True 2024-03-22 16:13:29 +01:00
Jelmer
26336b41f6
Merge pull request #510 from adamchainz/time_machine
Switch from freezegun to time-machine.
2024-03-22 15:46:19 +01:00
Guilherme Martins Crocetti
22015b8e69
chore(monitor-field): Add deprecation warning when the field is null and no default is provided. The new behavior will be introduced in a next major release 2024-03-21 20:05:14 -03:00
Jelmer
6e7158bfa0
Merge pull request #516 from jayvdb/allow-sqlite-testing
Allow running tests using sqlite
2024-03-21 15:41:12 +01:00
Maarten ter Huurne
a1530ad838 Update where ConnectionDoesNotExist is imported from
It was moved to a different package in Django 3.2.
2024-03-21 14:18:19 +01:00
Joseph Riddle
55cd816939
Merge branch 'master' into fix-prefetch-related 2023-11-27 12:55:53 -08:00
Adam Johnson
11f3a53b0f Remove SaveSignalHandlingModel 2023-10-26 16:56:30 +01:00
Serhii Tereshchenko
0ec4ac5e38
fix: Use proper column name instead of attname (#573)
fix: Use proper column name instead of attname
2023-06-16 15:34:47 +02:00
joeriddles
103c942ca5 Fix docstring for prefetch_related test class 2023-01-26 14:25:43 -08:00
joeriddles
604c6f0b62 Remove unnecessary model and simplify tests for prefetch_related 2023-01-26 14:25:09 -08:00
joeriddles
a0624f1492 For error on prefetch_related for tracked field 2023-01-26 13:17:49 -08:00
Hasan Ramezani
0b5475e3d5 Add pyupgrade to pre-commit configurations 2022-08-17 23:08:31 +02:00
Hasan Ramezani
b354d90c20 Drop support for Django < 3.2 2022-08-17 23:08:29 +02:00
Tim Gates
2dab8afded docs: Fix a few typos
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>
2022-08-17 22:37:49 +02:00
Adam Johnson
262ac384ac explicit timezones 2022-04-04 12:04:38 +01:00
Adam Johnson
8edd7c00fc Switch from freezegun to time-machine.
It’s [more accurate](https://adamj.eu/tech/2020/06/03/introducing-time-machine/) and [faster](https://adamj.eu/tech/2021/02/19/freezegun-versus-time-machine/).
2022-04-04 11:53:18 +01:00
John Vandenberg
70963149d4 tests.settings: Update backend path 2021-12-26 13:49:49 +08:00
John Vandenberg
e6833a2d52 Allow running tests using sqlite 2021-12-26 12:31:12 +08:00
Hasan Ramezani
e418711f32 Add USE_TZ setting. 2021-12-08 12:33:23 +01:00
Ghassan Maslamani
b65a2ee41d set deafult DB_host as localhost 2021-10-10 23:27:56 +06: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
Nafees Anwar
9deb39dc46 Added deconstruct 2021-04-30 21:40:39 +05:00
Nafees Anwar
a56d07cd68 Added urlsafe token field 2021-04-30 21:40:39 +05:00
Hasan Ramezani
22cbfb6aeb
Rewrite test with subTest and remove parameterized from requirements-test. 2020-12-05 20:24:07 +01:00
Hasan Ramezani
f9fae60551
Remove duplicate test. 2020-12-05 20:13:04 +01:00
Hasan Ramezani
2269f810c8 Fix TypeError in save when model inherits from both TimeStampModel and StatusModel. (Fixes GH-465) 2020-12-02 00:07:22 +01:00
David Smith
79ff8ea6be
Used isort to sort imports (#460) 2020-11-29 20:58:00 +00:00
Jannis Leidel
415742ccdf
Fix typo. 2020-11-29 14:54:45 +01:00
Jannis Leidel
5b3672b980
Run Postgres 10 during testing. 2020-11-29 14:51:26 +01:00
Hasan Ramezani
4ec3ecdade Fix flake8 errors. 2020-11-29 13:36:33 +01:00
Hasan Ramezani
92ff6b927f Remove codes related to old versions of Django. 2020-11-28 21:46:25 +01:00
Hasan Ramezani
79cbc96055 Replace ugettext_lazy with gettext_lazy in test models to satisfy Django deprecation warning. 2020-11-28 19:26:34 +01:00
Arseniy Panfilov
b302580283 use empty set instead of a dict for an 'empty set' test case 2020-10-15 15:51:33 +06:00
Arseniy Panfilov
fdd3af34d9 failing tests with different types of arguments for 'updated_fields' 2020-10-15 15:51:33 +06:00
H. Buğra Aydın
2ad67e77b1
Add status_changed field to upload_fields parameter during save if status field is present (#441)
* implementation/tests

* naming problem
2020-09-17 20:34:57 +06:00
Craig Anderson
b7a160936f Add available_objects soft deletable model manager. Emit deprecation warning when using objects soft deletable manager. 2020-08-25 16:40:09 +06:00
Craig Anderson
eb00f65c81 Change assert calls to avoid deprecation warnings. 2020-08-12 16:33:07 +06:00
Skia
33e46ebd53 managers: avoid querying too much tables when not needed
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

```
2020-07-08 16:59:05 +06:00
H. Buğra Aydın
3e32ae257b Overriding TimeStampedModel's save() method (#412)
* 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
2020-01-23 13:19:06 +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