Opened 4 years ago

Closed 4 years ago

#32108 closed Cleanup/optimization (fixed)

Allowing null values while registering function on transaction on_commit

Reported by: Shagun Khemka Owned by: Herbert Poul
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: DjangoORM Transaction
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

So if I were to try this command:-

transaction.on_commit(None)

and run any sample tests which has simple django db post_save signal in the flow and it has functions which run on transaction commit, the code would crash with error

TypeError: 'NoneType' object is not callable.

So how about if we do not allow it to register as none beforehand or allow it to exit gracefully?

Change History (5)

comment:1 by Simon Charette, 4 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

I guess we could add a callable guard in transaction.on_commit to make tracing easier like we did in Signal.connect

https://github.com/django/django/blob/b26ec77deb7c5052163ef8514ec7db70c0a5ea2a/django/dispatch/dispatcher.py#L90

comment:2 by Mariusz Felisiak, 4 years ago

Easy pickings: set

comment:3 by Herbert Poul, 4 years ago

Has patch: set
Owner: changed from nobody to Herbert Poul
Status: newassigned

comment:4 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In c897b158:

Fixed #32108 -- Made transaction.on_commit() raise TypeError when callback is not a callable.

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