{{{#!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.
* version: 4.0 => dev
* component: Uncategorized => Documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/33939#comment:1>
* 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>
* owner: nobody => Alex Morega
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33939#comment:3>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/15981 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33939#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33939#comment:5>
* 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>
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>
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>