﻿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
37373	Deprecate QuerySet.extra(select, where, order_by)	Simon Charette	Simon Charette	"When the Expressions API was introduced to the ORM more than decade ago it paved the way for the safer injection of developer controlled SQL.

In the weeks that followed the feature landing in `main` the future of `extra()` [https://groups.google.com/g/django-developers/c/FojuU0syO8Y was discussed on the mailing list] and reached a consensus that [https://github.com/django/django/commit/e8cd65f8297928d3fa7ad3d338953a4423028713 the documentation should discourage its usage] #25213, direct users to file a ticket with the `extra` keyword if they encounter a use case they believe would still require its usage, and state that we would no longer be improving or fixing bugs for it.

Over the past decade all the tickets [https://code.djangoproject.com/query?component=Database+layer+(models%2C+ORM)&description=~extra&keywords=~extra&status=closed&order=id&desc=1&col=id&col=summary&col=component&col=owner&col=type tagged accordingly] have been triaged as achievable using the Expression API, early limitations such as [https://groups.google.com/g/django-developers/c/FojuU0syO8Y/m/5NOKchNyDgAJ not being able to filter by `RawSQL` expressions] have [https://github.com/django/django/commit/4137fc2efce2dde48340728b8006fc6d66b9e3a5 been addressed] #25367, and implicit behaviour such as the way `extra(select)` affects the order of `SELECT` members [https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a have had] proper alternatives implemented #28900.

As the obsolescence of `extra(select, where, order_by)` was confirmed over the years new features were added without taking it into consideration and it slowly slipped into abandon as it became [https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a a torn in the way of refactors] and [https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a functionally defunct] I think the time has come to consider fully deprecating it except for the `tables` option which cannot be emulated with the Expressions API yet #5929.

Since `extra(select, where, order_by)` has been around for almost as long as the project itself I suggest keeping shims meant to also be removed over the few internal `extra` methods and attributes of `sql.Query` during the deprecation period to allow third-party applications to gracefully stop relying on them."	Cleanup/optimization	assigned	Database layer (models, ORM)	6.1	Normal		extra		Unreviewed	0	0	0	0	0	0
