Fixed #33733 -- Preserved wrapper assignment for manager methods.

This commit is contained in:
kshivakumar 2022-05-24 17:55:35 +05:30 committed by Mariusz Felisiak
parent 0982cf2a01
commit 46efd03d26
2 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import copy
import inspect
from functools import wraps
from importlib import import_module
from django.db import router
@ -81,11 +82,10 @@ class BaseManager:
@classmethod
def _get_queryset_methods(cls, queryset_class):
def create_method(name, method):
@wraps(method)
def manager_method(self, *args, **kwargs):
return getattr(self.get_queryset(), name)(*args, **kwargs)
manager_method.__name__ = method.__name__
manager_method.__doc__ = method.__doc__
return manager_method
new_methods = {}

View File

@ -1,3 +1,4 @@
import inspect
import threading
from datetime import datetime, timedelta
from unittest import mock
@ -740,6 +741,13 @@ class ManagerTest(SimpleTestCase):
self.assertEqual(Article.objects.get.__doc__, models.QuerySet.get.__doc__)
self.assertEqual(Article.objects.count.__name__, models.QuerySet.count.__name__)
def test_manager_method_signature(self):
self.assertEqual(
str(inspect.signature(Article.objects.bulk_create)),
"(objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, "
"update_fields=None, unique_fields=None)",
)
class SelectOnSaveTests(TestCase):
def test_select_on_save(self):