Merge lp:~cmiller/desktopcouch/put_record_documented_more into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Chad Miller
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~cmiller/desktopcouch/put_record_documented_more
Merge into: lp:desktopcouch
Diff against target: 63 lines (+20/-14)
2 files modified
desktopcouch/records/doc/records.txt (+19/-4)
desktopcouch/records/server_base.py (+1/-10)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/put_record_documented_more
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Review via email: mp+20166@code.launchpad.net

Commit message

Make it clear that a owner of a record will get their data mutated when they call put_record, and that the result is safe to put again, with no need to fetch it from the server.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks clear to me

review: Approve
126. By Chad Miller

More ACHTUNG.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/doc/records.txt'
2--- desktopcouch/records/doc/records.txt 2009-11-11 16:24:22 +0000
3+++ desktopcouch/records/doc/records.txt 2010-02-25 19:47:14 +0000
4@@ -19,16 +19,31 @@
5
6 >>> r['c'] = ['d','e','f']
7
8-Save the record into the database with put_record:
9+Save the record into the database and update its ID and REV with
10+put_record. Before you put the record the first time, the ID and REV
11+may be unset:
12
13+>>> r.record_id is None
14+True
15+>>> r.record_revision is None
16+True
17 >>> record_id = db.put_record(r)
18
19+The record r is ready to be sent again, since put_record has side-effects
20+that mutate it.
21+
22+>>> r.record_id is not None
23+True
24+>>> r.record_revision is not None
25+True
26+>>> r['g'] = 'h'
27+>>> record_id = db.put_record(r) # HAS SIDE-EFFECT! Mutates r!
28+
29 Fetch existing records from the database by ID:
30
31 >>> fetched = db.get_record(record_id)
32->>> print fetched['a']
33-b
34->>>
35+>>> print fetched['g']
36+h
37
38 There is no ad-hoc query functionality.
39
40
41=== modified file 'desktopcouch/records/server_base.py'
42--- desktopcouch/records/server_base.py 2010-02-04 23:14:37 +0000
43+++ desktopcouch/records/server_base.py 2010-02-25 19:47:14 +0000
44@@ -199,19 +199,10 @@
45 record.record_id = uuid4().hex
46 self.db[record.record_id] = record._data
47
48- # At this point, we've saved new document to the database, by
49- # we do not know the revision number of it. We need *a*
50- # specific revision now, so that we can attach BLOBs to it.
51-
52- # This is bad. We can get the most recent revision, but that
53- # doesn't assure us that what we're attaching records to is
54- # the revision we just sent.
55-
56- retrieved_document = self.db[record.record_id]
57 for attachment_name in record.list_attachments():
58 data, content_type = record.attachment_data(attachment_name)
59 self.db.put_attachment(
60- retrieved_document, data, attachment_name, content_type)
61+ record._data, data, attachment_name, content_type)
62
63 return record.record_id
64

Subscribers

People subscribed via source and target branches