lp_save gives HTTP Error 412: Precondition Failed when adding a comment to a bug, but adds the comment anyway

Bug #341950 reported by Ursula Junque
10
Affects Status Importance Assigned to Milestone
launchpadlib
New
Undecided
Eleanor Berger

Bug Description

When trying to add a comment to a bug, it throws a HTTPError exception, but adds the comment.

Steps to reproduce:
1) Having a lp authenticated object:
>>> bug = lp.bugs[2112]
>>> bug.newMessage(content="Testing bug", subject="Testing add comment")
<message at https://api.staging.launchpad.net/beta/launchpad-foundations/+bug/2112/comments/9>
>>> bug.lp_save()
HTTPError: HTTP Error 412: Precondition Failed

Checking the bug page, it shows the added comment.

This may be related to bug 336866.

Tags: api
Ursula Junque (ursinha)
Changed in malone:
assignee: nobody → intellectronica
description: updated
Revision history for this message
Martin Pitt (pitti) wrote :

I get this problem when trying to set a duplicate:

>>> b.duplicate_of
>>> b.duplicate_of = 341478
>>> b.lp_save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/launchpadlib/resource.py", line 489, in lp_save
    URI(self.self_link), representation, headers)
  File "/usr/lib/python2.6/dist-packages/launchpadlib/_browser.py", line 266, in patch
    'PATCH', extra_headers=extra_headers)
  File "/usr/lib/python2.6/dist-packages/launchpadlib/_browser.py", line 212, in _request
    raise HTTPError(response, content)
launchpadlib.errors.HTTPError: HTTP Error 412: Precondition Failed

And unlike for comments, it does not actually set the duplicate, so the HTTPError cannot just be ignored.

Revision history for this message
Markus Korn (thekorn) wrote :
Download full text (5.8 KiB)

I did some debugging, and for me it looks like the http_etag attribute of an entry object is not updated properly as a result of a SEND request

markus@thekorn ~ % launchpad-shell --debug
send: 'GET /beta/ HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="92420252", oauth_timestamp="1237192827", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="DKXXXXXXXX", oauth_signature="&cNYYYYYYY"\r\nif-none-match: "6824f160547b20004d582a2e240f8317e4304abd"\r\nte: deflate, gzip\r\naccept: application/vd.sun.wadl+xml\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 304 Not Modified\r\n'
header: Date: Mon, 16 Mar 2009 08:40:28 GMT
header: Server: zope.server.http (HTTP)
header: Etag: "6824f160547b20004d582a2e240f8317e4304abd"
header: Vary: Cookie,Authorization,Accept
send: 'GET /beta/ HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="63109900", oauth_timestamp="1237192833", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="DKXXXXXXXX", oauth_signature="&cNYYYYYYY"\r\nif-none-match: "77546fc558d4a811ad4f71a3495af2e410a87c52"\r\nte: deflate, gzip\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 304 Not Modified\r\n'
header: Date: Mon, 16 Mar 2009 08:40:34 GMT
header: Server: zope.server.http (HTTP)
header: Etag: "77546fc558d4a811ad4f71a3495af2e410a87c52"
header: Vary: Cookie,Authorization,Accept
Welcome to launchpad-shell - an interactive shell using launchpadlib

You are using the following configuration:
  * credentials: <launchpadlib.credentials.Credentials object at 0x1830410>
  * service: https://api.staging.launchpad.net/beta/
  * cache: /home/markus/.launchpadlib/cache

In [1]: bug = launchpad.bugs[123456]
send: 'GET /beta/bugs/123456 HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="10785042", oauth_timestamp="1237192858", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="DKXXXXXXXX", oauth_signature="&cNYYYYYYY"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: ''
send: 'GET /beta/bugs/123456 HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="10785042", oauth_timestamp="1237192858", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="DKXXXXXXXX", oauth_signature="&cNYYYYYYY"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 200 Ok\r\n'
header: Date: Mon, 16 Mar 2009 08:41:00 GMT
header: Server: zope.server.http (HTTP)
header: X-Powered-By: Zope (www.zope.org), Python (www.python.org)
header: Content-Type: application/json
header: Content-Length: 1918
header...

Read more...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.