﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36051	Declare arity on aggregate functions	Jacob Walls	Jacob Walls	"Calling a database function with an incorrect number of arguments raises `TypeError` if the function declares its [https://docs.djangoproject.com/en/5.1/ref/models/expressions/#django.db.models.Func.arity arity]. We could improve the DX around CompositePrimaryKey by leveraging this feature, instead of just [https://github.com/django/django/blob/8d9901c961bf9d5cfa6bddddbbcebfbf487a5125/docs/topics/composite-primary-key.txt#L150 advising] to be careful.

The docs sort of imply some kind of error is raised (""# ERROR""), but this test passes:

{{{#!diff
diff --git a/tests/composite_pk/test_aggregate.py b/tests/composite_pk/test_aggregate.py
index b5474c5218..750618a277 100644
--- a/tests/composite_pk/test_aggregate.py
+++ b/tests/composite_pk/test_aggregate.py
@@ -1,5 +1,5 @@
 from django.db import NotSupportedError
-from django.db.models import Count, Q
+from django.db.models import Count, Max, Q
 from django.test import TestCase
 
 from .models import Comment, Tenant, User
@@ -32,6 +32,10 @@ class CompositePKAggregateTests(TestCase):
         cls.comment_5 = Comment.objects.create(id=5, user=cls.user_3, text=""barbaz"")
         cls.comment_6 = Comment.objects.create(id=6, user=cls.user_3, text=""baz"")
 
+    def test_max_pk(self):
+        # Could raise TypeError instead.
+        self.assertEqual(Comment.objects.aggregate(Max(""pk"")), {'pk__max': 1})
+
     def test_users_annotated_with_comments_id_count(self):
         user_1, user_2, user_3 = User.objects.annotate(Count(""comments__id"")).order_by(
             ""pk""
}}}

Relatedly, most of the built-in aggregate functions should set `arity=1`, which I'll include in a separate commit, but we can also discuss whether that needs to go through a deprecation path."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
