Skip to content

Commit

Permalink
Merge branch 'lenient-wrapping' into jsonobject
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyroberts committed Sep 13, 2013
2 parents e12e556 + bbc542d commit 06457fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions couchdbkit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,13 @@ def __init__(self, fetch, arg, wrapper, schema, params):
assert not (wrapper and schema)
wrap_doc = params.get('wrap_doc', schema is not None)
if schema:
schema = maybe_schema_wrapper(None, schema, params)
schema_wrapper = maybe_schema_wrapper(schema, params)
def row_wrapper(row):
data = row.get('value')
docid = row.get('id')
doc = row.get('doc')
if doc is not None and wrap_doc:
return schema(doc)
return schema_wrapper(doc)
elif not data or data is None:
return row
elif not isinstance(data, dict) or not docid:
Expand All @@ -929,7 +929,7 @@ def row_wrapper(row):
data['_id'] = docid
if 'rev' in data:
data['_rev'] = data.pop('rev')
return schema(data)
return schema_wrapper(data)
else:
def row_wrapper(row):
return row
Expand Down
6 changes: 4 additions & 2 deletions couchdbkit/schema/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def wrap(doc):


def schema_wrapper(schema, dynamic_properties=None):
if hasattr(schema, "wrap") and hasattr(schema, '_doc_type') and not dynamic_properties:
return schema.wrap
mapping = schema_map(schema, dynamic_properties)
return get_multi_wrapper(mapping)


def maybe_schema_wrapper(wrapper, schema, params):
def maybe_schema_wrapper(schema, params):
dynamic_properties = params.pop('dynamic_properties', None)
return wrapper or schema_wrapper(schema, dynamic_properties)
return schema_wrapper(schema, dynamic_properties)
5 changes: 5 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,12 @@ class Bar(Foo):

result = Foo.view('_all_docs', include_docs=True)
self.assertEqual(len(result), 1)
result.all()

from couchdbkit.exceptions import DocTypeError
result = Foo.view('_all_docs', include_docs=True, classes={
'Foo': Foo,
})
with self.assertRaises(DocTypeError):
result.all()
finally:
Expand Down

0 comments on commit 06457fa

Please sign in to comment.