diff --git a/django/db/models/manager.py b/django/db/models/manager.py index e37e56cd17a..467e79f9b9f 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -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 = {} diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 601dda762b8..44ace3d6849 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -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):