Commit graph

126 commits

Author SHA1 Message Date
Benedikt Willi
f09ea0e472 Fix compatibility issues with django-modeltranslation by modifying manager mixins
- Added a new class `_GenericMixin` to serve as a runtime placeholder for `Generic[ModelT]`. This change prevents `TypeError` during `__class__` assignments, which was an issue when mixins inherited from `Generic[T]` at runtime.
- All manager mixins have been updated to inherit from `_GenericMixin` instead of `Generic[ModelT]`. This ensures compatibility with `django-modeltranslation`.
- Introduced regressions tests to confirm that the manager instances support `__class__` reassignment without issues. Tests were added for `SoftDeletableManager`, `InheritanceManager`, `QueryManager`, and `JoinManager`.

Closes GH-#636.
2025-12-15 11:38:33 +01:00
Guilherme Martins Crocetti
1673feae7b
chore: Replicate Django's signature at SoftDelete queryset 2024-08-28 10:41:31 -03:00
Maarten ter Huurne
1db7d6ba33 Fix type generics in InheritanceIterable 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
ecc7312bf4 Override signature of query-returning methods in InheritanceManager 2024-06-13 12:02:05 +02:00
Maarten ter Huurne
bde2d8f9a9 Annotate the managers 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
04e152f879 Do not assume that default manager is named objects in join() 2024-06-13 12:02:05 +02:00
Jelmer
2d833de9fa
Merge pull request #615 from ProtixIT/deprecate-joinmanager
Deprecate `JoinManager` and `JoinManagerMixin`
2024-05-14 08:15:38 +02:00
Maarten ter Huurne
2b2110f82e Remove JoinQueryset.get_quoted_query()
Pass the parameters to the DB API instead of quoting them ourselves.
2024-05-02 12:47:40 +02:00
Maarten ter Huurne
784bf50c09 Add deprecation warning to JoinManagerMixin 2024-04-17 14:45:16 +02:00
Jelmer Draaijer
ae562b45fb Remove unused code 2024-03-21 16:52:14 +01:00
Jelmer
89b7662fa8
Merge pull request #567 from ProtixIT/remove-clone-args
Remove arguments from `InheritanceQuerySetMixin._clone()`
2024-03-21 15:33:02 +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
Maarten ter Huurne
033fca4e2d Remove arguments from InheritanceQuerySetMixin._clone()
The `QuerySet._clone()` method has no arguments in either Django 3.2
or 4.1, so I'm assuming the arguments were necessary for a version
of Django that is no longer supported by `django-model-utils`.
2023-04-19 22:14:27 +02:00
Hasan Ramezani
0b5475e3d5 Add pyupgrade to pre-commit configurations 2022-08-17 23:08:31 +02:00
Adam Johnson
d699745504 Remove workaround from select_subclasess()
The workaround was for an issue that was fixed in Django 1.7: https://code.djangoproject.com/ticket/16855 / 349c12d3f5 .
2022-08-17 23:06:50 +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
tumb1er
dd0f62bdba Fix QuerySet._chain for django main (post-3.2) 2021-10-09 16:52:50 +06:00
David Smith
79ff8ea6be
Used isort to sort imports (#460) 2020-11-29 20:58:00 +00:00
Hasan Ramezani
92ff6b927f Remove codes related to old versions of Django. 2020-11-28 21:46:25 +01: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
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
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
Rémy HUBSCHER
976c17024e
Merge branch 'master' into instance-of 2019-08-20 12:50:09 +02:00
Skia
1b9b5ac2c1 managers: honor OneToOneField.parent_link=False (#363) 2019-03-12 23:29:02 +06:00
Sebastian Illing
326bd7bc02 Fix missing subclasses and annotated in cloned InheritanceQueryset (#335)
Bug only occurs in django > 2
2018-12-08 11:26:36 +06:00
Jonathan Sundqvist
2cb773372d Add a JoinManager that helps with performance (#351)
* 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
2018-11-25 20:18:23 +06:00
Lucas Wiman
0859508a64 Fix E123 closing bracket does not match indentation of opening bracket's line 2018-07-02 12:57:14 -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
Hanley Hansen
18dfb6b2cf
Merge pull request #279 from hanleyhansen/inheritance-iterable
Update InheritanceIterable to inherit from ModelIterable instead of BaseIterable
2018-05-02 14:14:22 -04:00
Tony Narlock
c4d72123ef rm use_for_related_fields #290 2017-12-07 12:20:50 -06:00
Tony Narlock
a07140e771 Use _chain for django 2.0, #295 2017-12-07 11:13:39 -06:00
Hanley
0a809df4da make InheritanceIterable inherit from ModelIterable instead of BaseIterable 2017-06-23 09:51:32 -04:00
Sachi King
8cb21aabbc Support django 1.11 iterator changes
Django starting with 1.9 switched to using a class to provide an
iterator for the querymanager.  Between 1.9 and 1.10 changes slowly
stopped referencing that function and instead started calling
_iterator_class directly.

As the functionality model-utils is patching has moved, this patch moves
the iterator logic to a class to match the changes that have been made
in Django in version 1.9.

As Django 1.8 is a LTS release that is still supported, iterator()
is retained in the InheritanceQuerySetMixin and can be removed when
support for Django 1.8 is removed.  This goes for the try-except in the
import statements as well.
2017-04-02 21:53:15 +10:00
Romain G
d07b992b94 Drop old get_query_set syntax, replaced by get_queryset now 2017-01-12 18:34:47 +00:00
Ryan P Kilby
e148c670d1 Fix django 2.0 warnings 2017-01-12 12:16:46 -05:00
Ryan P Kilby
fda2d39ec4 Drop unsupported django versions 2017-01-12 12:16:40 -05:00
Bruno Alla
2af54972eb Revert unrelated change regarding related fields
Remove attribute use_for_related_fields in SoftDeletableManagerMixin.
2017-01-05 18:32:13 +00:00
Bruno Alla
063332643d Split SoftDeletableQuerySet/Manager into Mixin 2017-01-05 14:40:03 +00:00
Bruno Alla
0efaad1218 Fix issue when extend QuerySet and Manager - fixes #249 2017-01-05 14:29:35 +00:00
Radosław Ganczarek
9e90dde2e8 Add SoftDeletableModel 2016-09-12 15:11:34 +02:00
Artis Avotins
d1337d5a7c Fixed a bug with Django >= 1.9 where values_list was called on
InheritanceQuerySet with `select_subclasses` applied as strings
raised AttributeError exception.

Adds a new test case `test_dj19_values_list_on_select_subclasses`
2016-05-25 18:58:03 +02:00
Adam Bogdał
4f39ce9497 Add support for Django 1.10 2016-02-09 00:22:12 +01:00
Karl WnW
ce8deed5ca Fix _clone signature for Django<1.9
InheritanceQuerySetMixin._clone signature conflicts with django
ValuesQuerySet._clone code which calls super like this:
"c = super(ValuesQuerySet, self)._clone(klass, **kwargs)"
2015-11-02 17:52:43 +01:00
jarekwg
bbad2b7b47 Hide _clone params in kwargs to match django 1.9 signature 2015-10-29 02:00:49 +11:00
jarekwg
2824ec2e48 Remove PassThroughManager
As of Django 1.7, QuerySet.as_manager() achieves the same result.
2015-10-29 00:10:28 +11:00
Carl Meyer
3f9b1cfac8 Fix select_subclasses for Django 1.8. 2015-01-27 16:48:06 -07:00