Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6d90ce250a | ||
|
ea31846a19 | ||
|
e6317776c1 |
@@ -2,6 +2,11 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Changes in 0.6.12
|
||||
=================
|
||||
- Fixes scalar lookups for primary_key
|
||||
- Fixes error with _delta handling DBRefs
|
||||
|
||||
Changes in 0.6.11
|
||||
==================
|
||||
- Fixed inconsistency handling None values field attrs
|
||||
|
@@ -12,7 +12,7 @@ from signals import *
|
||||
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
|
||||
queryset.__all__ + signals.__all__)
|
||||
|
||||
VERSION = (0, 6, 11)
|
||||
VERSION = (0, 6, 12)
|
||||
|
||||
|
||||
def get_version():
|
||||
|
@@ -1043,11 +1043,16 @@ Invalid data to create a `%s` instance.\n%s""".strip() % (cls._class_name, error
|
||||
for path in set_fields:
|
||||
parts = path.split('.')
|
||||
d = doc
|
||||
new_path = []
|
||||
for p in parts:
|
||||
if p.isdigit():
|
||||
if isinstance(d, DBRef):
|
||||
break
|
||||
elif p.isdigit():
|
||||
d = d[int(p)]
|
||||
else:
|
||||
elif hasattr(d, 'get'):
|
||||
d = d.get(p)
|
||||
new_path.append(p)
|
||||
path = '.'.join(new_path)
|
||||
set_data[path] = d
|
||||
else:
|
||||
set_data = doc
|
||||
|
@@ -226,7 +226,7 @@ class Document(BaseDocument):
|
||||
if cascade_kwargs: # Allow granular control over cascades
|
||||
kwargs.update(cascade_kwargs)
|
||||
kwargs['_refs'] = _refs
|
||||
self._changed_fields = []
|
||||
#self._changed_fields = []
|
||||
self.cascade_save(**kwargs)
|
||||
|
||||
except pymongo.errors.OperationFailure, err:
|
||||
@@ -246,6 +246,7 @@ class Document(BaseDocument):
|
||||
"""Recursively saves any references / generic references on an object"""
|
||||
from fields import ReferenceField, GenericReferenceField
|
||||
_refs = kwargs.get('_refs', []) or []
|
||||
|
||||
for name, cls in self._fields.items():
|
||||
if not isinstance(cls, (ReferenceField, GenericReferenceField)):
|
||||
continue
|
||||
|
@@ -1496,8 +1496,6 @@ class QuerySet(object):
|
||||
def lookup(obj, name):
|
||||
chunks = name.split('__')
|
||||
for chunk in chunks:
|
||||
if hasattr(obj, '_db_field_map'):
|
||||
chunk = obj._db_field_map.get(chunk, chunk)
|
||||
obj = getattr(obj, chunk)
|
||||
return obj
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
%define srcname mongoengine
|
||||
|
||||
Name: python-%{srcname}
|
||||
Version: 0.6.11
|
||||
Version: 0.6.12
|
||||
Release: 1%{?dist}
|
||||
Summary: A Python Document-Object Mapper for working with MongoDB
|
||||
|
||||
|
@@ -1667,6 +1667,48 @@ class DocumentTest(unittest.TestCase):
|
||||
self.assertEquals(p.owns[0], o)
|
||||
self.assertEquals(o.owner, p)
|
||||
|
||||
def test_circular_reference_deltas_2(self):
|
||||
|
||||
class Person( Document ):
|
||||
name = StringField()
|
||||
owns = ListField( ReferenceField( 'Organization' ) )
|
||||
employer = ReferenceField( 'Organization' )
|
||||
|
||||
class Organization( Document ):
|
||||
name = StringField()
|
||||
owner = ReferenceField( 'Person' )
|
||||
employees = ListField( ReferenceField( 'Person' ) )
|
||||
|
||||
Person.drop_collection()
|
||||
Organization.drop_collection()
|
||||
|
||||
person = Person( name="owner" )
|
||||
person.save()
|
||||
|
||||
employee = Person( name="employee" )
|
||||
employee.save()
|
||||
|
||||
organization = Organization( name="company" )
|
||||
organization.save()
|
||||
|
||||
person.owns.append( organization )
|
||||
organization.owner = person
|
||||
|
||||
organization.employees.append( employee )
|
||||
employee.employer = organization
|
||||
|
||||
person.save()
|
||||
organization.save()
|
||||
employee.save()
|
||||
|
||||
p = Person.objects.get(name="owner")
|
||||
e = Person.objects.get(name="employee")
|
||||
o = Organization.objects.first()
|
||||
|
||||
self.assertEquals(p.owns[0], o)
|
||||
self.assertEquals(o.owner, p)
|
||||
self.assertEquals(e.employer, o)
|
||||
|
||||
def test_delta(self):
|
||||
|
||||
class Doc(Document):
|
||||
|
@@ -3006,6 +3006,19 @@ class QuerySetTest(unittest.TestCase):
|
||||
self.assertEqual(plist[1], (20, False))
|
||||
self.assertEqual(plist[2], (30, True))
|
||||
|
||||
def test_scalar_primary_key(self):
|
||||
|
||||
class SettingValue(Document):
|
||||
key = StringField(primary_key=True)
|
||||
value = StringField()
|
||||
|
||||
SettingValue.drop_collection()
|
||||
s = SettingValue(key="test", value="test value")
|
||||
s.save()
|
||||
|
||||
val = SettingValue.objects.scalar('key', 'value')
|
||||
self.assertEqual(list(val), [('test', 'test value')])
|
||||
|
||||
def test_scalar_cursor_behaviour(self):
|
||||
"""Ensure that a query returns a valid set of results.
|
||||
"""
|
||||
|
Reference in New Issue
Block a user