Skip to content

Commit

Permalink
Fix for inheritance bug and db_alias
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Jul 20, 2012
1 parent 83c11a9 commit 3070e0b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
7 changes: 6 additions & 1 deletion docs/changelog.rst
Expand Up @@ -2,9 +2,14 @@
Changelog
=========


Changes in 0.6.16
=================
- Fixed issue where db_alias wasn't inherited

Changes in 0.6.15
=================
- Updated validation error message
- Updated validation error messages
- Added support for null / zero / false values in item_frequencies
- Fixed cascade save edge case
- Fixed geo index creation through reference fields
Expand Down
2 changes: 1 addition & 1 deletion mongoengine/__init__.py
Expand Up @@ -12,7 +12,7 @@
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
queryset.__all__ + signals.__all__)

VERSION = (0, 6, 15)
VERSION = (0, 6, 16)


def get_version():
Expand Down
15 changes: 8 additions & 7 deletions mongoengine/base.py
Expand Up @@ -649,8 +649,13 @@ def __new__(cls, name, bases, attrs):
del(attrs['meta']['collection'])
if base._get_collection_name():
collection = base._get_collection_name()
# Propagate index options.
for key in ('index_background', 'index_drop_dups', 'index_opts'):

# Propagate inherited values
keys_to_propogate = (
'index_background', 'index_drop_dups', 'index_opts',
'allow_inheritance', 'queryset_class', 'db_alias',
)
for key in keys_to_propogate:
if key in base._meta:
base_meta[key] = base._meta[key]

Expand All @@ -659,18 +664,14 @@ def __new__(cls, name, bases, attrs):
abstract_base_indexes += base._meta.get('indexes', [])
else:
base_indexes += base._meta.get('indexes', [])
# Propagate 'allow_inheritance'
if 'allow_inheritance' in base._meta:
base_meta['allow_inheritance'] = base._meta['allow_inheritance']
if 'queryset_class' in base._meta:
base_meta['queryset_class'] = base._meta['queryset_class']
try:
base_meta['objects'] = base.__getattribute__(base, 'objects')
except TypeError:
pass
except AttributeError:
pass

# defaults
meta = {
'abstract': False,
'collection': collection,
Expand Down
2 changes: 1 addition & 1 deletion python-mongoengine.spec
Expand Up @@ -5,7 +5,7 @@
%define srcname mongoengine

Name: python-%{srcname}
Version: 0.6.15
Version: 0.6.16
Release: 1%{?dist}
Summary: A Python Document-Object Mapper for working with MongoDB

Expand Down
14 changes: 13 additions & 1 deletion tests/test_document.py
Expand Up @@ -2999,7 +2999,7 @@ class Book(Document):
self.assertEqual(User.objects.first(), bob)
self.assertEqual(Book.objects.first(), hp)

# DeRefecence
# DeReference
class AuthorBooks(Document):
author = ReferenceField(User)
book = ReferenceField(Book)
Expand Down Expand Up @@ -3027,6 +3027,18 @@ class AuthorBooks(Document):
self.assertEqual(Book._get_collection(), get_db("testdb-2")[Book._get_collection_name()])
self.assertEqual(AuthorBooks._get_collection(), get_db("testdb-3")[AuthorBooks._get_collection_name()])

def test_db_alias_propagates(self):
"""db_alias propagates?
"""
class A(Document):
name = StringField()
meta = {"db_alias": "testdb-1", "allow_inheritance": True}

class B(A):
pass

self.assertEquals('testdb-1', B._meta.get('db_alias'))

def test_db_ref_usage(self):
""" DB Ref usage in __raw__ queries """

Expand Down

0 comments on commit 3070e0b

Please sign in to comment.