0

I need to save a django many-to-many field to a third-party server when saving a model. However, the third party server might be unavailable, in which case I need to abort the whole save operation.

Is it possible to abort saving a model from the m2m_changed phase?

Ozzee
  • 1
  • 1
    Yeah. If unavailable just call `instance.delete()` or in the `save` method check availability of the service and then save. – karthikr Jul 16 '13 at 12:04

1 Answers1

0

Yes, and this is officially supported by the transactions framework. It basically allows you to save (outside the database) what would be the database changes until you actually tell him to commit that change.

By waiting for a third party, you can commit or discard the transaction. This can even be made on a request/response basis, by the transaction's middleware.

Be careful though about the version you are using of Django, as transactions suffered some changes on 1.6.

Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121