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
=== modified file 'desktopcouch/records/doc/records.txt'
--- desktopcouch/records/doc/records.txt 2009-11-11 16:24:22 +0000
+++ desktopcouch/records/doc/records.txt 2010-02-25 19:47:14 +0000
@@ -19,16 +19,31 @@
1919
20>>> r['c'] = ['d','e','f']20>>> r['c'] = ['d','e','f']
2121
22Save the record into the database with put_record:22Save the record into the database and update its ID and REV with
23put_record. Before you put the record the first time, the ID and REV
24may be unset:
2325
26>>> r.record_id is None
27True
28>>> r.record_revision is None
29True
24>>> record_id = db.put_record(r)30>>> record_id = db.put_record(r)
2531
32The record r is ready to be sent again, since put_record has side-effects
33that mutate it.
34
35>>> r.record_id is not None
36True
37>>> r.record_revision is not None
38True
39>>> r['g'] = 'h'
40>>> record_id = db.put_record(r) # HAS SIDE-EFFECT! Mutates r!
41
26Fetch existing records from the database by ID:42Fetch existing records from the database by ID:
2743
28>>> fetched = db.get_record(record_id)44>>> fetched = db.get_record(record_id)
29>>> print fetched['a']45>>> print fetched['g']
30b46h
31>>>
3247
33There is no ad-hoc query functionality.48There is no ad-hoc query functionality.
3449
3550
=== modified file 'desktopcouch/records/server_base.py'
--- desktopcouch/records/server_base.py 2010-02-04 23:14:37 +0000
+++ desktopcouch/records/server_base.py 2010-02-25 19:47:14 +0000
@@ -199,19 +199,10 @@
199 record.record_id = uuid4().hex199 record.record_id = uuid4().hex
200 self.db[record.record_id] = record._data200 self.db[record.record_id] = record._data
201201
202 # At this point, we've saved new document to the database, by
203 # we do not know the revision number of it. We need *a*
204 # specific revision now, so that we can attach BLOBs to it.
205
206 # This is bad. We can get the most recent revision, but that
207 # doesn't assure us that what we're attaching records to is
208 # the revision we just sent.
209
210 retrieved_document = self.db[record.record_id]
211 for attachment_name in record.list_attachments():202 for attachment_name in record.list_attachments():
212 data, content_type = record.attachment_data(attachment_name)203 data, content_type = record.attachment_data(attachment_name)
213 self.db.put_attachment(204 self.db.put_attachment(
214 retrieved_document, data, attachment_name, content_type)205 record._data, data, attachment_name, content_type)
215206
216 return record.record_id207 return record.record_id
217208

Subscribers

People subscribed via source and target branches