Skip to content

Commit f0230e6

Browse files
rdbismedjc
authored andcommitted
Fix to issue djc#278
Added an if statement in the _wrap_row method of couchdb.mapping.Document to ensure the correct handling of the revision '_rev' key inside the _data dictionary the class uses to wrap data from the database Added the test_wrapped_view unittest related to this change
1 parent 9141667 commit f0230e6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

couchdb/mapping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ def _wrap_row(cls, row):
406406
return cls.wrap(doc)
407407
data = row['value']
408408
data['_id'] = row['id']
409+
if 'rev' in data: # When data is client.Document
410+
data['_rev'] = data['rev']
409411
return cls.wrap(data)
410412

411413

couchdb/tests/mapping.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ def test_view(self):
242242
include_docs=True)
243243
self.assertEqual(type(results.rows[0]), self.Item)
244244

245+
def test_wrapped_view(self):
246+
self.Item().store(self.db)
247+
results = self.db.view('_all_docs', wrapper=self.Item._wrap_row)
248+
doc = results.rows[0]
249+
self.db.delete(doc)
250+
245251
def test_query(self):
246252
self.Item().store(self.db)
247253
results = self.Item.query(self.db, all_map_func, None)

0 commit comments

Comments
 (0)