[Django]-Django: Stacking decorators

7👍

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.

👤AKX

Leave a comment