fix-#789: abstract shouldn't be inherited in EmbeddedDocument
This commit is contained in:
		| @@ -5,6 +5,7 @@ Changelog | |||||||
|  |  | ||||||
| Changes in 0.9.X - DEV | Changes in 0.9.X - DEV | ||||||
| ====================== | ====================== | ||||||
|  | - abstract shouldn't be inherited in EmbeddedDocument # 789 | ||||||
| - Allow specifying the '_cls' as a field for indexes #397 | - Allow specifying the '_cls' as a field for indexes #397 | ||||||
| - Stop ensure_indexes running on a secondaries unless connection is through mongos #746 | - Stop ensure_indexes running on a secondaries unless connection is through mongos #746 | ||||||
| - Not overriding default values when loading a subset of fields #399 | - Not overriding default values when loading a subset of fields #399 | ||||||
|   | |||||||
| @@ -46,8 +46,9 @@ class DocumentMetaclass(type): | |||||||
|                 elif hasattr(base, '_meta'): |                 elif hasattr(base, '_meta'): | ||||||
|                     meta.merge(base._meta) |                     meta.merge(base._meta) | ||||||
|             attrs['_meta'] = meta |             attrs['_meta'] = meta | ||||||
|  |             attrs['_meta']['abstract'] = False  # 789: EmbeddedDocument shouldn't inherit abstract | ||||||
|  |  | ||||||
|         if '_meta' in attrs and attrs['_meta'].get('allow_inheritance', ALLOW_INHERITANCE): |         if attrs['_meta'].get('allow_inheritance', ALLOW_INHERITANCE): | ||||||
|             StringField = _import_class('StringField') |             StringField = _import_class('StringField') | ||||||
|             attrs['_cls'] = StringField() |             attrs['_cls'] = StringField() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -397,6 +397,16 @@ class InheritanceTest(unittest.TestCase): | |||||||
|                 meta = {'abstract': True} |                 meta = {'abstract': True} | ||||||
|         self.assertRaises(ValueError, create_bad_abstract) |         self.assertRaises(ValueError, create_bad_abstract) | ||||||
|  |  | ||||||
|  |     def test_abstract_embedded_documents(self): | ||||||
|  |         # 789: EmbeddedDocument shouldn't inherit abstract | ||||||
|  |         class A(EmbeddedDocument): | ||||||
|  |             meta = {"abstract": True} | ||||||
|  |  | ||||||
|  |         class B(A): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         self.assertFalse(B._meta["abstract"]) | ||||||
|  |  | ||||||
|     def test_inherited_collections(self): |     def test_inherited_collections(self): | ||||||
|         """Ensure that subclassed documents don't override parents' |         """Ensure that subclassed documents don't override parents' | ||||||
|         collections |         collections | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user