Comment 11 for bug 336866

Revision history for this message
Martin Pitt (pitti) wrote :

I found a workaround for this now. Previously I was doing

           bug = self.launchpad.bugs[id]

            for a in bug.attachments:
                if a.title in (...):
                    try:
                        a.removeFromBug()
                    except HTTPError:
                        pass # workaround for 404 error, see LP #315387

            # MARKER1
            if not bug.duplicate_of:
                bug.duplicate_of = master

           self.launchpad.lp_save() # MARKER2

This gave me the afforementioned 412 error. After a looong time of fiddling, I found out the following:

  * Deleting attachmends and then changing properties leads to this error in lp_save()
  * Calling lp_save() twice in a row leads to this error.

So what I did to circumvent the crash:

 * at MARKER1: get a new bug object with "bug = self.launchpad.bugs[id]"

  * at MARKER2:

       if bug._dirty_attributes: # avoid "412: Precondition Failed"
            bug.lp_save()

I really shouldn't have to explicitly query a private attribute (_dirty_attributes). If it's empty, lp_save() should just be a no-op.