Opened 14 months ago

Closed 13 months ago

Last modified 11 months ago

#33939 closed Cleanup/optimization (fixed)

Change docs for transaction.on_commit to suggest functools.partial instead of lambda

Reported by: Alex Morega Owned by: Alex Morega
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've recently got bitten by a silly bug:

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 functools.partial instead of lambda. The above example becomes:

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.

Change History (8)

comment:1 Changed 14 months ago by Alex Morega

Component: UncategorizedDocumentation
Version: 4.0dev

comment:2 Changed 13 months ago by Carlton Gibson

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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

comment:3 Changed 13 months ago by Alex Morega

Owner: changed from nobody to Alex Morega
Status: newassigned

comment:4 Changed 13 months ago by Alex Morega

Has patch: set

comment:5 Changed 13 months ago by Carlton Gibson

Triage Stage: AcceptedReady for checkin

comment:6 Changed 13 months ago by GitHub <noreply@…>

Resolution: fixed
Status: assignedclosed

In 7e6b537f:

Fixed #33939 -- Used functools.partial() in transaction.on_commit() examples.

comment:7 Changed 13 months ago by Carlton Gibson <carlton.gibson@…>

In 8a8a0038:

[4.1.x] Fixed #33939 -- Used functools.partial() in transaction.on_commit() examples.

Backport of 7e6b537f5b92be152779fc492bb908d27fe7c52a from main

comment:8 Changed 11 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 444b6da7:

Refs #33939 -- Improved transaction.on_commit() docs.

Note: See TracTickets for help on using tickets.
Back to Top