Opened 2 years ago

Closed 2 years ago

Last modified 2 years 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, 2 years ago

Component: UncategorizedDocumentation
Version: 4.0dev

comment:2 by Carlton Gibson, 2 years 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, 2 years ago

Owner: changed from nobody to Alex Morega
Status: newassigned

comment:4 by Alex Morega, 2 years ago

Has patch: set

comment:5 by Carlton Gibson, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by GitHub <noreply@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 7e6b537f:

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

comment:7 by Carlton Gibson <carlton.gibson@…>, 2 years 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@…>, 2 years ago

In 444b6da7:

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

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