diff --git a/docs/changelog.rst b/docs/changelog.rst index 92770afb..d93bf13c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,10 @@ Changelog ========= +Changes in 0.7.9 +================ +- Better fix handling for old style _types +- Embedded SequenceFields follow collection naming convention Changes in 0.7.8 ================ diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index 08cabaa1..b67512d7 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -12,7 +12,7 @@ from signals import * __all__ = (document.__all__ + fields.__all__ + connection.__all__ + queryset.__all__ + signals.__all__) -VERSION = (0, 7, 8) +VERSION = (0, 7, 9) def get_version(): diff --git a/mongoengine/base.py b/mongoengine/base.py index 208e0e59..013afe78 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -122,9 +122,11 @@ def get_document(name): doc = _document_registry.get(name, None) if not doc: # Possible old style name - end = name.split('.')[-1] - possible_match = [k for k in _document_registry.keys() if k == end] - if len(possible_match) == 1 and end != name: + single_end = name.split('.')[-1] + compound_end = '.%s' % single_end + possible_match = [k for k in _document_registry.keys() + if k.endswith(compound_end) or k == single_end] + if len(possible_match) == 1: doc = _document_registry.get(possible_match.pop(), None) if not doc: raise NotRegistered(""" diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 213c2148..de484a1d 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -1364,7 +1364,8 @@ class SequenceField(IntField): if issubclass(owner, Document): return owner._get_collection_name() else: - return owner._class_name + return ''.join('_%s' % c if c.isupper() else c + for c in owner._class_name).strip('_').lower() def __get__(self, instance, owner): diff --git a/python-mongoengine.spec b/python-mongoengine.spec index f175546b..b1ec3361 100644 --- a/python-mongoengine.spec +++ b/python-mongoengine.spec @@ -5,7 +5,7 @@ %define srcname mongoengine Name: python-%{srcname} -Version: 0.7.8 +Version: 0.7.9 Release: 1%{?dist} Summary: A Python Document-Object Mapper for working with MongoDB diff --git a/tests/test_document.py b/tests/test_document.py index a09aaeca..cd0ab8fb 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -15,7 +15,7 @@ from datetime import datetime from tests.fixtures import Base, Mixin, PickleEmbedded, PickleTest from mongoengine import * -from mongoengine.base import NotRegistered, InvalidDocumentError +from mongoengine.base import NotRegistered, InvalidDocumentError, get_document from mongoengine.queryset import InvalidQueryError from mongoengine.connection import get_db, get_connection @@ -1336,7 +1336,6 @@ class DocumentTest(unittest.TestCase): User.drop_collection() - def test_document_not_registered(self): class Place(Document): @@ -1361,6 +1360,19 @@ class DocumentTest(unittest.TestCase): print Place.objects.all() self.assertRaises(NotRegistered, query_without_importing_nice_place) + def test_document_registry_regressions(self): + + class Location(Document): + name = StringField() + meta = {'allow_inheritance': True} + + class Area(Location): + location = ReferenceField('Location', dbref=True) + + Location.drop_collection() + + self.assertEquals(Area, get_document("Area")) + self.assertEquals(Area, get_document("Location.Area")) def test_creation(self): """Ensure that document may be created using keyword arguments. diff --git a/tests/test_fields.py b/tests/test_fields.py index 0483519e..28af1b23 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -2201,7 +2201,7 @@ class FieldTest(unittest.TestCase): comments=[Comment(content="NoSQL Rocks"), Comment(content="MongoEngine Rocks")]).save() - c = self.db['mongoengine.counters'].find_one({'_id': 'Comment.id'}) + c = self.db['mongoengine.counters'].find_one({'_id': 'comment.id'}) self.assertEqual(c['next'], 2) post = Post.objects.first() self.assertEqual(1, post.comments[0].id)