Merge lp:~cjwatson/lazr.restful/stable-dict-etag into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 297
Proposed branch: lp:~cjwatson/lazr.restful/stable-dict-etag
Merge into: lp:lazr.restful
Prerequisite: lp:~cjwatson/lazr.restful/datetime-unmarshall
Diff against target: 48 lines (+8/-1)
3 files modified
NEWS.rst (+2/-0)
src/lazr/restful/docs/webservice-marshallers.rst (+2/-0)
src/lazr/restful/marshallers.py (+4/-1)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/stable-dict-etag
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+402906@code.launchpad.net

Commit message

Generate stable ETags for dict fields.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS.rst'
2--- NEWS.rst 2021-05-18 15:17:15 +0000
3+++ NEWS.rst 2021-05-18 15:17:15 +0000
4@@ -8,6 +8,8 @@
5 Give ``DateTimeFieldMarshaller`` an ``unmarshall`` method, rather than
6 special-casing it elsewhere.
7
8+Generate stable ETags for dict fields.
9+
10 1.0.2 (2021-05-14)
11 ==================
12
13
14=== modified file 'src/lazr/restful/docs/webservice-marshallers.rst'
15--- src/lazr/restful/docs/webservice-marshallers.rst 2021-05-18 15:17:15 +0000
16+++ src/lazr/restful/docs/webservice-marshallers.rst 2021-05-18 15:17:15 +0000
17@@ -1000,6 +1000,8 @@
18 ['Dessert', 'Vegetarian']
19
20 >>> unmarshalled = dict_marshaller.unmarshall(None, marshalled_dict)
21+ >>> print(type(unmarshalled).__name__)
22+ OrderedDict
23 >>> for key, value in sorted(unmarshalled.items()):
24 ... print('%s: %s' % (key, value))
25 bar: General
26
27=== modified file 'src/lazr/restful/marshallers.py'
28--- src/lazr/restful/marshallers.py 2021-05-18 15:17:15 +0000
29+++ src/lazr/restful/marshallers.py 2021-05-18 15:17:15 +0000
30@@ -24,6 +24,7 @@
31 'VocabularyLookupFieldMarshaller',
32 ]
33
34+from collections import OrderedDict
35 from datetime import datetime
36 from io import BytesIO
37 import re
38@@ -579,7 +580,9 @@
39 """
40 if value is None:
41 return value
42- return dict(
43+ # Use an ordered dict so that fields using this marshaller have a
44+ # stable ETag.
45+ return OrderedDict(
46 (self.key_marshaller.unmarshall(entry, key),
47 self.value_marshaller.unmarshall(entry, val))
48 for key, val in value.items())

Subscribers

People subscribed via source and target branches