[Django] #33939: Change docs for transaction.on_commit to suggest functools.partial instead of lambda

40 views
Skip to first unread message

Django

unread,
Aug 19, 2022, 2:06:48 PM8/19/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-----------------------------------------+------------------------
Reporter: Alex Morega | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I've recently got bitten by a silly bug:

{{{#!python
for n in range(10):
transaction.on_commit(lambda: do_something(n))
}}}

Of course, instead of calling `do_something(0)`, `do_something(1)` ...,
it's going to call `do_something(9)` 10 times.

The docs could help by suggesting
[https://docs.python.org/3/library/functools.html#functools.partial
functools.partial] instead of `lambda`. The above example becomes:

{{{#!python
for n in range(10):
transaction.on_commit(partial(do_something, n))
}}}

If this change is a good idea I can have a go at making a PR.

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

Django

unread,
Aug 19, 2022, 2:07:13 PM8/19/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------+--------------------------------------

Reporter: Alex Morega | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Alex Morega):

* version: 4.0 => dev
* component: Uncategorized => Documentation


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

Django

unread,
Aug 22, 2022, 3:34:58 AM8/22/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
--------------------------------------+------------------------------------

Reporter: Alex Morega | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Hey Alex. OK... I might be a bit marginal but, certainly happy to look at
a PR if you're keen to make it.

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

Django

unread,
Aug 22, 2022, 3:41:42 AM8/22/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: assigned

Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alex Morega):

* owner: nobody => Alex Morega
* status: new => assigned


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

Django

unread,
Aug 22, 2022, 10:11:35 AM8/22/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15981 PR]

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

Django

unread,
Aug 23, 2022, 4:10:11 AM8/23/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | 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 Carlton Gibson):

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 23, 2022, 5:56:22 AM8/23/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | 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 GitHub <noreply@…>):

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


Comment:

In [changeset:"7e6b537f5b92be152779fc492bb908d27fe7c52a" 7e6b537f]:
{{{
#!CommitTicketReference repository=""
revision="7e6b537f5b92be152779fc492bb908d27fe7c52a"
Fixed #33939 -- Used functools.partial() in transaction.on_commit()
examples.
}}}

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

Django

unread,
Aug 23, 2022, 5:59:53 AM8/23/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"8a8a00388b065b3a7c43f7b0d887f64c81a367b8" 8a8a0038]:
{{{
#!CommitTicketReference repository=""
revision="8a8a00388b065b3a7c43f7b0d887f64c81a367b8"
[4.1.x] Fixed #33939 -- Used functools.partial() in
transaction.on_commit() examples.

Backport of 7e6b537f5b92be152779fc492bb908d27fe7c52a from main
}}}

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

Django

unread,
Nov 4, 2022, 7:51:59 AM11/4/22
to django-...@googlegroups.com
#33939: Change docs for transaction.on_commit to suggest functools.partial instead
of lambda
-------------------------------------+-------------------------------------
Reporter: Alex Morega | Owner: Alex
Type: | Morega
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"444b6da7cc229a58a2c476a52e45233001dc7073" 444b6da7]:
{{{
#!CommitTicketReference repository=""
revision="444b6da7cc229a58a2c476a52e45233001dc7073"
Refs #33939 -- Improved transaction.on_commit() docs.
}}}

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

Reply all
Reply to author
Forward
0 new messages