Merge lp:~wallyworld/lazr.restfulclient/named-post-url-change-1056546 into lp:lazr.restfulclient

Proposed by Ian Booth
Status: Merged
Approved by: Curtis Hovey
Approved revision: 136
Merged at revision: 133
Proposed branch: lp:~wallyworld/lazr.restfulclient/named-post-url-change-1056546
Merge into: lp:lazr.restfulclient
Diff against target: 80 lines (+28/-4)
5 files modified
src/lazr/restfulclient/NEWS.txt (+6/-0)
src/lazr/restfulclient/docs/operations.txt (+13/-0)
src/lazr/restfulclient/resource.py (+7/-2)
src/lazr/restfulclient/version.txt (+1/-1)
versions.cfg (+1/-1)
To merge this branch: bzr merge lp:~wallyworld/lazr.restfulclient/named-post-url-change-1056546
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+126375@code.launchpad.net

Commit message

If a Location header is in a named operation post response, use it as the replacement url for the resource.

Description of the change

A named post operation may result in the resource on which the post is operating to have a different url at the end of the operation. When the lazr restful client has finished making the api call, it invokes lp_refresh() to get the new state of the resource, and this fails with a 404 if the url has changed, since the old url is all the client knows about.

I added a bit of code to detect the 301 response and reload the resource if necessary.

I added a dependency on the corresponding new lazr.resful lib and updated a doctest to reflect the new behaviour.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you. Users do not install this lib. I doubt it will even be backported to LTS releases, so I expect users will still see this problem for years after we release the fix.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restfulclient/NEWS.txt'
--- src/lazr/restfulclient/NEWS.txt 2012-06-19 13:47:10 +0000
+++ src/lazr/restfulclient/NEWS.txt 2012-09-26 11:13:26 +0000
@@ -2,6 +2,12 @@
2NEWS for lazr.restfulclient2NEWS for lazr.restfulclient
3===========================3===========================
44
50.13.1 (2012-09-26)
6===================
7
8 - Named POST operations may result in a resource moving to a new location.
9 Detect the redirect and reload the resource from its new URL.
10
50.13.0 (2012-06-19)110.13.0 (2012-06-19)
6===================12===================
713
814
=== modified file 'src/lazr/restfulclient/docs/operations.txt'
--- src/lazr/restfulclient/docs/operations.txt 2011-11-18 20:38:06 +0000
+++ src/lazr/restfulclient/docs/operations.txt 2012-09-26 11:13:26 +0000
@@ -74,6 +74,19 @@
74 >>> print cookbook.find_recipe_for(dish=dish)74 >>> print cookbook.find_recipe_for(dish=dish)
75 None75 None
7676
77A named operation may change the resource's location so we get a 301 response
78with the new URL.
79
80 >>> from urllib import quote
81 >>> from lazr.restful.testing.webservice import WebServiceCaller
82 >>> webservice = WebServiceCaller(domain='cookbooks.dev')
83 >>> url = quote("/cookbooks/New cookbook")
84 >>> print webservice.named_post(url, 'make_more_interesting')
85 HTTP/1.1 301 Moved Permanently
86 ...
87 Location: http://cookbooks.dev/devel/cookbooks/The%20New%20New%20cookbook
88 ...
89
77JSON-encoding90JSON-encoding
78-------------91-------------
7992
8093
=== modified file 'src/lazr/restfulclient/resource.py'
--- src/lazr/restfulclient/resource.py 2012-06-19 11:58:42 +0000
+++ src/lazr/restfulclient/resource.py 2012-09-26 11:13:26 +0000
@@ -589,8 +589,13 @@
589 else:589 else:
590 if http_method == 'post':590 if http_method == 'post':
591 # The method call probably modified this resource in591 # The method call probably modified this resource in
592 # an unknown way. Refresh its representation.592 # an unknown way. If it moved to a new location, reload it or
593 self.resource.lp_refresh()593 # else just refresh its representation.
594 if response.status == 301:
595 url = response['location']
596 response, content = self.root._browser._request(url)
597 else:
598 self.resource.lp_refresh()
594 return self._handle_200_response(url, response, content)599 return self._handle_200_response(url, response, content)
595600
596 def _handle_201_response(self, url, response, content):601 def _handle_201_response(self, url, response, content):
597602
=== modified file 'src/lazr/restfulclient/version.txt'
--- src/lazr/restfulclient/version.txt 2012-06-19 13:47:10 +0000
+++ src/lazr/restfulclient/version.txt 2012-09-26 11:13:26 +0000
@@ -1,1 +1,1 @@
10.13.010.13.1
22
=== modified file 'versions.cfg'
--- versions.cfg 2012-06-19 13:28:22 +0000
+++ versions.cfg 2012-09-26 11:13:26 +0000
@@ -25,7 +25,7 @@
25lazr.delegates = 1.2.025lazr.delegates = 1.2.0
26lazr.enum = 1.1.226lazr.enum = 1.1.2
27lazr.lifecycle = 1.027lazr.lifecycle = 1.0
28lazr.restful = 0.19.228lazr.restful = 0.19.7
29lazr.uri = 1.0.229lazr.uri = 1.0.2
30lxml = 2.2.730lxml = 2.2.7
31martian = 0.1131martian = 0.11

Subscribers

People subscribed via source and target branches