Opened 20 months ago

Closed 20 months ago

Last modified 18 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 by Alex Morega, 20 months ago

Component: UncategorizedDocumentation
Version: 4.0dev

comment:2 by Carlton Gibson, 20 months ago

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 by Alex Morega, 20 months ago

Owner: changed from nobody to Alex Morega
Status: newassigned

comment:4 by Alex Morega, 20 months ago

Has patch: set

comment:5 by Carlton Gibson, 20 months ago

Triage Stage: AcceptedReady for checkin

comment:6 by GitHub <noreply@…>, 20 months ago

Resolution: fixed
Status: assignedclosed

In 7e6b537f:

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

comment:7 by Carlton Gibson <carlton.gibson@…>, 20 months ago

In 8a8a0038:

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

Backport of 7e6b537f5b92be152779fc492bb908d27fe7c52a from main

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 18 months ago

In 444b6da7:

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

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