Skip to content

Commit

Permalink
Fix ReferenceField dbref = False
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Sep 18, 2012
1 parent 7cd38c5 commit ab4d4e6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

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

Changes in 0.7.4
================
Expand Down
2 changes: 1 addition & 1 deletion mongoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
queryset.__all__ + signals.__all__)

VERSION = (0, 7, 4)
VERSION = (0, 7, 5)


def get_version():
Expand Down
2 changes: 1 addition & 1 deletion mongoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def to_mongo(self, document):
collection = self.document_type._get_collection_name()
return DBRef(collection, id_)

return "%s" % id_
return id_

def to_python(self, value):
"""Convert a MongoDB-compatible type to a Python type.
Expand Down
2 changes: 1 addition & 1 deletion python-mongoengine.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%define srcname mongoengine

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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_dereference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import with_statement
import unittest

from bson import DBRef
from bson import DBRef, ObjectId

from mongoengine import *
from mongoengine.connection import get_db
Expand Down Expand Up @@ -187,8 +187,8 @@ class Group(Document):
self.assertEqual(group.members, [user])

raw_data = Group._get_collection().find_one()
self.assertTrue(isinstance(raw_data['author'], basestring))
self.assertTrue(isinstance(raw_data['members'][0], basestring))
self.assertTrue(isinstance(raw_data['author'], ObjectId))
self.assertTrue(isinstance(raw_data['members'][0], ObjectId))

def test_recursive_reference(self):
"""Ensure that ReferenceFields can reference their own documents.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from decimal import Decimal

from bson import Binary, DBRef
from bson import Binary, DBRef, ObjectId
import gridfs

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

def test_str_reference_fields(self):
def test_objectid_reference_fields(self):

class Person(Document):
name = StringField()
Expand All @@ -1117,7 +1117,7 @@ class Person(Document):

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

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

0 comments on commit ab4d4e6

Please sign in to comment.