Skip to content

Commit ab4d4e6

Browse files
committed
Fix ReferenceField dbref = False
1 parent 7cd38c5 commit ab4d4e6

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
Changes in 0.7.5
6+
================
7+
- ReferenceFields with dbref=False use ObjectId instead of strings (MongoEngine/mongoengine#134)
8+
See ticket for upgrade notes (https://github.com/MongoEngine/mongoengine/issues/134)
59

610
Changes in 0.7.4
711
================

mongoengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
1313
queryset.__all__ + signals.__all__)
1414

15-
VERSION = (0, 7, 4)
15+
VERSION = (0, 7, 5)
1616

1717

1818
def get_version():

mongoengine/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def to_mongo(self, document):
792792
collection = self.document_type._get_collection_name()
793793
return DBRef(collection, id_)
794794

795-
return "%s" % id_
795+
return id_
796796

797797
def to_python(self, value):
798798
"""Convert a MongoDB-compatible type to a Python type.

python-mongoengine.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%define srcname mongoengine
66

77
Name: python-%{srcname}
8-
Version: 0.7.4
8+
Version: 0.7.5
99
Release: 1%{?dist}
1010
Summary: A Python Document-Object Mapper for working with MongoDB
1111

tests/test_dereference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import with_statement
22
import unittest
33

4-
from bson import DBRef
4+
from bson import DBRef, ObjectId
55

66
from mongoengine import *
77
from mongoengine.connection import get_db
@@ -187,8 +187,8 @@ class Group(Document):
187187
self.assertEqual(group.members, [user])
188188

189189
raw_data = Group._get_collection().find_one()
190-
self.assertTrue(isinstance(raw_data['author'], basestring))
191-
self.assertTrue(isinstance(raw_data['members'][0], basestring))
190+
self.assertTrue(isinstance(raw_data['author'], ObjectId))
191+
self.assertTrue(isinstance(raw_data['members'][0], ObjectId))
192192

193193
def test_recursive_reference(self):
194194
"""Ensure that ReferenceFields can reference their own documents.

tests/test_fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from decimal import Decimal
99

10-
from bson import Binary, DBRef
10+
from bson import Binary, DBRef, ObjectId
1111
import gridfs
1212

1313
from nose.plugins.skip import SkipTest
@@ -1104,7 +1104,7 @@ class Person(Document):
11041104
p = Person.objects.get(name="Ross")
11051105
self.assertEqual(p.parent, p1)
11061106

1107-
def test_str_reference_fields(self):
1107+
def test_objectid_reference_fields(self):
11081108

11091109
class Person(Document):
11101110
name = StringField()
@@ -1117,7 +1117,7 @@ class Person(Document):
11171117

11181118
col = Person._get_collection()
11191119
data = col.find_one({'name': 'Ross'})
1120-
self.assertEqual(data['parent'], "%s" % p1.pk)
1120+
self.assertEqual(data['parent'], p1.pk)
11211121

11221122
p = Person.objects.get(name="Ross")
11231123
self.assertEqual(p.parent, p1)

0 commit comments

Comments
 (0)