- 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.
* 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 required a bit of refactoring to get the type of `STATUS` correct
for each suite.
There are two cases which I decided not to support in the type system:
- passing a list instead of a tuple when defining an option group
- `in` checks using a data type that doesn't match the choices
There used to be a [bug in Django](https://code.djangoproject.com/ticket/30427)
that caused these tests to fail, according to the discussion of #370.
That bug was fixed in Django 4.0.
However, because the test model was using a `FieldTracker`
rather than a `ModelTracker`, all model-specific test cases
in `ModelTrackerTests` continued to fail.
Besides requiring less code, this also allows the django-stubs
mypy plugin to automatically generate a type-annotated version
of the manager.
Unfortunately, the plugin does not put a `ClassVar` annotation
on `objects`, which is why we need the suppression.
Avoid using `Self` as a type argument: for some reason this fails
when mypy has an empty cache, but passes when the cache has been
filled. Maybe it's a weird interaction between the mypy core and
the django-stubs plugin?
* Pass additional arguments to superclass `contribute_to_class()`
In Django 3.2 there is an additional argument `private_only` and more
could be added in future versions.
This module was support code for the `SaveSignalHandlingModel` tests.
That class got introduced in 5d6f8f4e and removed in 11f3a53b, but
the support code remained.
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.
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.