[Django] #25759: Add **kwargs to as_sql method of Expressions

21 views
Skip to first unread message

Django

unread,
Nov 16, 2015, 12:47:35 AM11/16/15
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords: expressions
Triage Stage: Accepted | Has patch: 0
Needs documentation: 1 | Needs tests: 1
Patch needs improvement: 1 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
A common pattern when overriding `as_sql` or implementing `as_vendor` with
expressions is to modify the template or function attributes before
rendering the expression. This isn't safe to do, because expressions can
be shared between backends.

It'd be a good idea to add `**kwargs` to the method signature, so that
overrides can add context to that specific method call without mutating
the expression itself. For expressions like `Func`, it could mix the
`kwargs` with `self.extra` during rendering. Unsure how `**kwargs` would
affect other expression types, but that can be opt in per type.

Once this is done, the documentation written for
https://github.com/django/django/pull/5574 for third party backend
overrides will need to be updated to take advantage of the new `kwargs`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25759>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 11, 2016, 9:17:59 PM2/11/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:

Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:1>

Django

unread,
Feb 12, 2016, 8:19:26 AM2/12/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: shekhar-
| singh
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by shekhar-singh):

* status: new => assigned
* owner: nobody => shekhar-singh


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:2>

Django

unread,
Feb 13, 2016, 5:24:25 AM2/13/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: shekhar-
| singh
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jarshwah):

Some notes for completing this ticket:

Start by adding **kwargs to the method signature of as_sql for all
expression types, including transforms and lookups. There are quite a few
places.

For Func, get rid of the function and template key word arguments, and
merge self.extra with **kwargs in a local variable (so you don't modify
self.extra), using that to generate the sql string.

Need to update docs to reference the new **kwargs argument and change any
tests that override as_sql for vendor specific tests so that they no
longer modify self.template or self.function.

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:3>

Django

unread,
Feb 14, 2016, 3:55:51 AM2/14/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by shekhar-singh):

* status: assigned => new
* owner: shekhar-singh =>


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:4>

Django

unread,
Feb 14, 2016, 12:22:56 PM2/14/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff

Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaifeldhoff):

* owner: => kaifeldhoff


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:5>

Django

unread,
Feb 15, 2016, 4:14:02 PM2/15/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaifeldhoff):

* has_patch: 0 => 1


Comment:

Pull request: [https://github.com/django/django/pull/6147]

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:6>

Django

unread,
Feb 21, 2016, 9:01:11 AM2/21/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaifeldhoff):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:7>

Django

unread,
Feb 25, 2016, 8:07:35 AM2/25/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* easy: 1 => 0


Comment:

Comments for improvement are on the pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:8>

Django

unread,
Mar 12, 2016, 12:50:43 PM3/12/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kaifeldhoff):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:9>

Django

unread,
Mar 14, 2016, 7:36:25 PM3/14/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:10>

Django

unread,
Mar 16, 2016, 7:14:08 AM3/16/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* stage: Ready for checkin => Accepted


Comment:

New PR: https://github.com/django/django/pull/6302

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:11>

Django

unread,
Mar 16, 2016, 11:45:38 AM3/16/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:12>

Django

unread,
Mar 21, 2016, 9:06:28 PM3/21/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"baa8b0ec399bd9b0ff3308666b49c6ab734aa416" baa8b0ec]:
{{{
#!CommitTicketReference repository=""
revision="baa8b0ec399bd9b0ff3308666b49c6ab734aa416"
Refs #25759 -- Fixed some Funcs to work if different database backends are
used.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:13>

Django

unread,
Mar 21, 2016, 9:06:28 PM3/21/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"5ca08f7cab4d65f9bd49bd8a1817dd4b6591cab1" 5ca08f7c]:
{{{
#!CommitTicketReference repository=""
revision="5ca08f7cab4d65f9bd49bd8a1817dd4b6591cab1"
Refs #25759 -- Documented customizing expressions' SQL on other databases.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:14>

Django

unread,
Mar 28, 2016, 1:56:52 PM3/28/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/6338 Updated PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:15>

Django

unread,
Mar 29, 2016, 9:09:23 AM3/29/16
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner:
| kaifeldhoff
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"53361589905c7c07692cd77f398ce6cb5ac39779" 53361589]:
{{{
#!CommitTicketReference repository=""
revision="53361589905c7c07692cd77f398ce6cb5ac39779"
Fixed #25759 -- Added keyword arguments to customize Expressions'
as_sql().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:16>

Django

unread,
Mar 29, 2017, 1:29:28 PM3/29/17
to django-...@googlegroups.com
#25759: Add **kwargs to as_sql method of Expressions
-------------------------------------+-------------------------------------
Reporter: Josh Smeaton | Owner: Kai
| Feldhoff

Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"d5977e492e6e8eb7ba0ac81f85c27d56db85b78c" d5977e49]:
{{{
#!CommitTicketReference repository=""
revision="d5977e492e6e8eb7ba0ac81f85c27d56db85b78c"
Refs #25759 -- Fixed some GIS Funcs if different database backends are
used.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25759#comment:17>

Reply all
Reply to author
Forward
0 new messages