Raise an error if trying to perform a join
You can't join across reference fields, so raise an error if someone tries to.
This commit is contained in:
parent
e9b8093dac
commit
2a391f0f16
@ -5,6 +5,7 @@ Changelog
|
|||||||
Changes in dev
|
Changes in dev
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
- Errors raised if trying to perform a join in a query
|
||||||
- Updates can now take __raw__ queries
|
- Updates can now take __raw__ queries
|
||||||
- Added custom 2D index declarations
|
- Added custom 2D index declarations
|
||||||
- Added replicaSet connection support
|
- Added replicaSet connection support
|
||||||
|
@ -610,6 +610,9 @@ class QuerySet(object):
|
|||||||
raise InvalidQueryError('Cannot resolve field "%s"'
|
raise InvalidQueryError('Cannot resolve field "%s"'
|
||||||
% field_name)
|
% field_name)
|
||||||
else:
|
else:
|
||||||
|
from mongoengine.fields import ReferenceField, GenericReferenceField
|
||||||
|
if isinstance(field, (ReferenceField, GenericReferenceField)):
|
||||||
|
raise InvalidQueryError('Cannot perform join in mongoDB: %s' % '__'.join(parts))
|
||||||
# Look up subfield on the previous field
|
# Look up subfield on the previous field
|
||||||
new_field = field.lookup_member(field_name)
|
new_field = field.lookup_member(field_name)
|
||||||
from base import ComplexBaseField
|
from base import ComplexBaseField
|
||||||
|
@ -10,6 +10,7 @@ from fixtures import Base, Mixin, PickleEmbedded, PickleTest
|
|||||||
|
|
||||||
from mongoengine import *
|
from mongoengine import *
|
||||||
from mongoengine.base import NotRegistered, InvalidDocumentError
|
from mongoengine.base import NotRegistered, InvalidDocumentError
|
||||||
|
from mongoengine.queryset import InvalidQueryError
|
||||||
from mongoengine.connection import get_db
|
from mongoengine.connection import get_db
|
||||||
|
|
||||||
|
|
||||||
@ -640,7 +641,7 @@ class DocumentTest(unittest.TestCase):
|
|||||||
location = DictField()
|
location = DictField()
|
||||||
meta = {
|
meta = {
|
||||||
'indexes': [
|
'indexes': [
|
||||||
'*location.point',
|
'*location.point',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
Place.drop_collection()
|
Place.drop_collection()
|
||||||
@ -2256,6 +2257,22 @@ class DocumentTest(unittest.TestCase):
|
|||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
|
def test_cannot_perform_joins_references(self):
|
||||||
|
|
||||||
|
class BlogPost(Document):
|
||||||
|
author = ReferenceField(self.Person)
|
||||||
|
author2 = GenericReferenceField()
|
||||||
|
|
||||||
|
def test_reference():
|
||||||
|
list(BlogPost.objects(author__name="test"))
|
||||||
|
|
||||||
|
self.assertRaises(InvalidQueryError, test_reference)
|
||||||
|
|
||||||
|
def test_generic_reference():
|
||||||
|
list(BlogPost.objects(author2__name="test"))
|
||||||
|
|
||||||
|
self.assertRaises(InvalidQueryError, test_generic_reference)
|
||||||
|
|
||||||
def test_duplicate_db_fields_raise_invalid_document_error(self):
|
def test_duplicate_db_fields_raise_invalid_document_error(self):
|
||||||
"""Ensure a InvalidDocumentError is thrown if duplicate fields
|
"""Ensure a InvalidDocumentError is thrown if duplicate fields
|
||||||
declare the same db_field"""
|
declare the same db_field"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user