changing bugtask attributes via api gives "412 precondition failed"

Bug #534066 reported by Martin Pool
24
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Critical
James Westby

Bug Description

When I try to set the importance of a bugtask through the api (using Hydrazine) it always fails with "412 Precondition Failed." This was working last week and now fails 100% of the time.

All the application code is doing is assigning to the importance field of a bugtask.

hydrazine(edge) #532600> importance wishlist
send: 'GET /beta/bugs/532600/bug_tasks HTTP/1.1\r\nHost: api.edge.launchpad.net\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="OAuth", oauth_nonce="82987347", oauth_timestamp="1268000275", oauth_consumer_key="Hydrazine", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="xxxxx", oauth_signature="xxxxx"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev$\r\n\r\n'
reply: 'HTTP/1.1 200 Ok\r\n'
header: Date: Sun, 07 Mar 2010 22:17:55 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: 1236
header: Vary: Cookie,Authorization,Accept
header: Via: 1.1 wildcard.edge.launchpad.net
changing importance Undecided => Wishlist
send: u'PATCH /beta/bzr/+bug/532600 HTTP/1.1\r\nHost: api.edge.launchpad.net\r\nAccept-Encoding: identity\r\nContent-Length: 26\r\nAuthorization: OAuth realm="OAuth", oauth_nonce="17729195", oauth_timestamp="1268000276", oauth_consumer_key="Hydrazine", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="xxxxx", oauth_signature="xxxxx"\r\ncontent-type: application/json\r\nif-match: "00046d87ab8e9d82d3775bb7d52db281d075c824"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev$\r\n\r\n'
send: '{"importance": "Wishlist"}'
reply: 'HTTP/1.1 412 Precondition Failed\r\n'
header: Date: Sun, 07 Mar 2010 22:17:56 GMT
header: Server: zope.server.http (HTTP)
header: X-Powered-By: Zope (www.zope.org), Python (www.python.org)
header: X-Content-Type-Warning: guessed from content
header: Content-Type: text/plain
header: Content-Length: 0
header: Vary: Cookie,Authorization,Accept
header: Via: 1.1 wildcard.edge.launchpad.net
HTTP Error 412: Precondition Failed
Response headers:
---
content-length: 0
content-type: text/plain
date: Sun, 07 Mar 2010 22:17:56 GMT
server: zope.server.http (HTTP)
status: 412
vary: Cookie,Authorization,Accept
via: 1.1 wildcard.edge.launchpad.net
x-content-type-warning: guessed from content
x-powered-by: Zope (www.zope.org), Python (www.python.org)
---
Response body:
---

---

hydrazine(edge) #532600>

Tags: api lp-bugs qa-ok

Related branches

Martin Pool (mbp)
tags: added: api
Revision history for this message
James Westby (james-w) wrote :

Martin,

Could you please dump the json of the task before you get the error, and then after a .lp_refresh()
after you get it. This will show whether something has changed, or there is an etag calculation issue.

This is a problem which there can be many causes for, and so we need to no which it is
before we can look at tackling it.

You can dump the json with something like

  print bug_task._wadl_resource._definition.representation

Doing bug_task.lp_refresh() will then fetch it again from the server and so printing the same
thing will show what changed, if anything.

Thanks,

James

Revision history for this message
Martin Pool (mbp) wrote :

I changed bugclient like so:

    def do_importance(self, line):
        """Set importance"""
        task = self._needs_single_task()
        if task is None:
            return
        new_importance = canonical_importance(line)
        if new_importance is None:
            return
        print 'changing importance %s => %s' % (task.importance, new_importance)
        task.importance = new_importance
        print '**** before save'
        if opts.debug:
            print task._wadl_resource._definition.representation
        try:
            task.lp_save()
        except:
            print '**** got error'
            if opts.debug:
                print task._wadl_resource._definition.representation

The before form is

{u'date_closed': None, u'task_age': 53680, u'date_assigned': None, u'title': u'Bug #532600 in Bazaar: "bzr diff --summarize"', u'bug_link': u'https://api.edge.launchpad.net/beta/bugs/532600', u'bug_watch_link': None, u'milestone_link': None, u'http_etag': u'"93faa3919aaa3a58289ace9b3cfa8d035f8fd49a"', u'date_left_closed': u'2010-03-05T22:45:34.103676+00:00', u'date_fix_committed': None, u'date_fix_released': None, u'self_link': u'https://api.edge.launchpad.net/beta/bzr/+bug/532600', u'resource_type_link': u'https://api.edge.launchpad.net/beta/#bug_task', u'status': u'Confirmed', u'bug_target_name': u'bzr', u'importance': u'Low', u'assignee_link': None, u'date_triaged': None, u'date_in_progress': None, u'target_link': u'https://api.edge.launchpad.net/beta/bzr', u'bug_target_display_name': u'Bazaar', u'related_tasks_collection_link': u'https://api.edge.launchpad.net/beta/bzr/+bug/532600/related_tasks', u'date_confirmed': u'2010-03-08T00:07:26.022635+00:00', u'date_left_new': u'2010-03-05T15:00:45.944280+00:00', u'owner_link': u'https://api.edge.launchpad.net/beta/~pelle-morth', u'date_created': u'2010-03-05T12:28:14.302618+00:00', u'is_complete': False}

the after form is

{u'date_closed': None, u'task_age': 53680, u'date_assigned': None, u'title': u'Bug #532600 in Bazaar: "bzr diff --summarize"', u'bug_link': u'https://api.edge.launchpad.net/beta/bugs/532600', u'bug_watch_link': None, u'milestone_link': None, u'http_etag': u'"93faa3919aaa3a58289ace9b3cfa8d035f8fd49a"', u'date_left_closed': u'2010-03-05T22:45:34.103676+00:00', u'date_fix_committed': None, u'date_fix_released': None, u'self_link': u'https://api.edge.launchpad.net/beta/bzr/+bug/532600', u'resource_type_link': u'https://api.edge.launchpad.net/beta/#bug_task', u'status': u'Confirmed', u'bug_target_name': u'bzr', u'importance': u'Low', u'assignee_link': None, u'date_triaged': None, u'date_in_progress': None, u'target_link': u'https://api.edge.launchpad.net/beta/bzr', u'bug_target_display_name': u'Bazaar', u'related_tasks_collection_link': u'https://api.edge.launchpad.net/beta/bzr/+bug/532600/related_tasks', u'date_confirmed': u'2010-03-08T00:07:26.022635+00:00', u'date_left_new': u'2010-03-05T15:00:45.944280+00:00', u'owner_link': u'https://api.edge.launchpad.net/beta/~pelle-morth', u'date_created': u'2010-03-05T12:28:14.302618+00:00', u'is_complete': False}

there doesn't seem to be any difference between them.

Revision history for this message
James Westby (james-w) wrote : Re: [Bug 534066] Re: can't update bugtask importance via api

On Mon, 08 Mar 2010 03:24:23 -0000, Martin Pool <email address hidden> wrote:
> there doesn't seem to be any difference between them.

OK, please ask a LOSA to check if all the edge appservers are on the
same revision currently, that's one thing that can break things in this
manner.

Thanks,

James

Revision history for this message
Martin Pool (mbp) wrote : Re: can't update bugtask importance via api

<mthaddon> poolie: they are, yes (the same as lpnet/production)

Revision history for this message
Martin Pool (mbp) wrote :

fwiw the same problem occurs when trying to retarget the task to a different product.

Martin Pool (mbp)
summary: - can't update bugtask importance via api
+ changing bugtask attributes via api gives "412 precondition failed"
Revision history for this message
Markus Korn (thekorn) wrote :

I can confirm this bug, all PATCH operations on bug_task objects fail in this way. As a workaround you can use bug_task.transitionTo* which is using POST and works fine.

Changed in malone:
status: New → Confirmed
Revision history for this message
Eleanor Berger (intellectronica) wrote :

Note that this workaround will not be working for long. AFAIK we're now in the process of modifying the API to block calls to mutator methods if the attribute they modify is exposed.

Revision history for this message
James Westby (james-w) wrote :

task_age is back in the representation, that's why you can't currently modify
anything with PATCH.

Thanks,

James

Revision history for this message
Eleanor Berger (intellectronica) wrote :

Wow, that's a surprise. I wonder how that happened. Maybe it slipped through some conflict resolution? Anyway, the fix is easy.

Changed in malone:
status: Confirmed → Triaged
importance: Undecided → High
Deryck Hodge (deryck)
Changed in malone:
importance: High → Critical
milestone: none → 10.03
assignee: nobody → James Westby (james-w)
Revision history for this message
Leonard Richardson (leonardr) wrote :

Ok, there's clearly a problem with the ETag generation. Fixing it will not fill fix all our 412 errors (eg. bug 336866), but it's a start.

task_age changes every second, which means the generated ETag changes every second, which means all PATCH requests will result in 412 errors. Clearly changes to task_age should not affect the generated ETag.

HOWEVER, by the same token, I suggest that task_age is useless and should not be published. If you are using launchpadlib you have no way of knowing how old your representation of a bugtask is. Maybe it's an hour old, maybe it's a day old. What's the right value for task_age? You don't know, and there's no way to find out. Changes to task_age don't affect the ETag, so you'll never be able to convince launchpadlib that it has an out-of-date representation. So long as nothing but task_age has changed, Launchpad will tell your client that it already has the most up-to-date representation.

task_age isn't even necessary, since you can subtract date_created from the current time. If I had to guessed I'd say it was published to make it easier to write some Ajax code, but it's causing more problems than it's worth, and I'm not confident that an Ajax application won't have the same problem with out-of-date values as launchpadlib. I suggest we get rid of the field.

That said, it's likely there are more fields that are screwing up the ETags in this way, and not all of them can simply be removed. What are the other candidates? And do you agree about getting rid of task_age?

Revision history for this message
Eleanor Berger (intellectronica) wrote :

Just to clarify, the immediate solution to this bug is the removal of task_age. This was already done last cycle by James but the code got reverted by mistake. See the branches attached.

Revision history for this message
Deryck Hodge (deryck) wrote :

Sorry I didn't make this clearer when I triaged this critical before. It's marked critical to help us ensure we get this branch of James' landed again, since a bad merge caused this to be removed, as Tom noted.

As for your other question, Leonard, I can't think of any other fields that are likely to cause this much of a problem.

Cheers,
deryck

Revision history for this message
Ursula Junque (ursinha) wrote : Bug fixed by a commit
Changed in malone:
status: Triaged → Fix Committed
tags: added: qa-needstesting
Revision history for this message
Deryck Hodge (deryck) wrote :

Can someone ack here that launchpadlib scripts are fixed now? James W. maybe?

Cheers,
deryck

Revision history for this message
Eleanor Berger (intellectronica) wrote : Re: [Bug 534066] Re: changing bugtask attributes via api gives "412 precondition failed"

On 10 March 2010 16:03, Deryck Hodge <email address hidden> wrote:
> Can someone ack here that launchpadlib scripts are fixed now?  James W.
> maybe?

Note that you can only test this on edge or staging for now. The fix
has not yet been rolled onto the main production servers.

Revision history for this message
Martin Pool (mbp) wrote :

On 11 March 2010 03:38, Tom Berger <email address hidden> wrote:
> On 10 March 2010 16:03, Deryck Hodge <email address hidden> wrote:
>> Can someone ack here that launchpadlib scripts are fixed now?  James W.
>> maybe?
>
> Note that you can only test this on edge or staging for now. The fix
> has not yet been rolled onto the main production servers.

nack, testing against staging using hydrazine bugclient shows the same
failure still occurs.

Just branch hydrazine and run

./bugclient --debug --staging -c 'pillar bzr' -c select_new -c 'triage
confirmed'

--
Martin <http://launchpad.net/~mbp/>

Martin Pool (mbp)
Changed in malone:
status: Fix Committed → In Progress
Revision history for this message
James Westby (james-w) wrote :

edge however is ok.

python -c 'from launchpadlib.launchpad import Launchpad; lp = Launchpad.login_with("testing", service_root="edge"); task = lp.bugs[12345].bug_tasks[0]; print hasattr(task, "task_age")'

should print False if all is ok.

I would hope that all LP developers were familiar enough with using the API that
you could knock up one-liners such as this yourselves :-)

Thanks,

James

Revision history for this message
Martin Pool (mbp) wrote :

Yes, working for me on edge now too.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Ursula Junque (ursinha) wrote :

Just a question: if the fix was committed but the bug was returned to In Progress, it should be marked as qa-bad, right?

Revision history for this message
Martin Pool (mbp) wrote :

On 11 March 2010 15:45, Ursula Junque <email address hidden> wrote:
> Just a question: if the fix was committed but the bug was returned to In
> Progress, it should be marked as qa-bad, right?

I don't know. I just thought I'd reopen it because it didn't work in
the way Tom said it would.

--
Martin <http://launchpad.net/~mbp/>

Deryck Hodge (deryck)
Changed in malone:
status: In Progress → Fix Committed
tags: added: qa-ok
removed: qa-needstesting
Revision history for this message
Deryck Hodge (deryck) wrote :

Thanks for the confirmation, Martin and James.

This was part QA and part follow up, which is why I didn't write the one-liner myself, James. ;)

Revision history for this message
Curtis Hovey (sinzui) wrote : Bug 534066 Fix released

Fixed released in launchpad-project 10.03.

Changed in malone:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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