diff --git a/couchdbkit/client.py b/couchdbkit/client.py index 142bcbf..7b1d418 100644 --- a/couchdbkit/client.py +++ b/couchdbkit/client.py @@ -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: @@ -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 diff --git a/couchdbkit/schema/util.py b/couchdbkit/schema/util.py index 20d149d..2069336 100644 --- a/couchdbkit/schema/util.py +++ b/couchdbkit/schema/util.py @@ -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) diff --git a/tests/test_schema.py b/tests/test_schema.py index 42cf3c5..972e0ec 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -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: