I have the following signal. Is it possible to 'stack' these two decorators as I did here?
@receiver(signal=charge_succeeded)
@transaction.atomic
def create_influencer_transaction(sender, order, charge, **kwargs):
pass
Yes.
Considering how decorators work, this is equivalent to
def create_influencer_transaction(sender, order, charge, **kwargs):
pass
create_influencer_transaction = transaction.atomic(
create_influencer_transaction
)
create_influencer_transaction = receiver(signal=charge_succeeded)(
create_influencer_transaction
)
– transaction.atomic will return a new function that has the atomicity wrapper logic, but receiver will just return the same function.
However, order here does matter (and you've got it right); if the decorators were the other way around, receiver would register the non-atomic version, which is not good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With