mongoengine
mongoengine copied to clipboard
Deepcopy - regex and Q querysets
Using a regex causes TypeError: cannot deepcopy this pattern object.
here is a sample code:
from mongoengine.connection import register_connection, DEFAULT_CONNECTION_NAME
from mongoengine import Document, StringField
from mongoengine.queryset import Q
import re
class Sample(Document):
name = StringField(max_length=200, required=True)
family = StringField(max_length=200, required=True)
def __unicode__(self):
return '{}.{}'.format(self.name, self.family)
print(mongoengine.VERSION)
# (0, 8, 7)
register_connection(DEFAULT_CONNECTION_NAME, 'test')
Sample.drop_collection()
s = Sample(name='omid', family='raha')
s.save()
print(Sample.objects.all())
# [<Sample: omid.raha>]
r = re.compile('omid', 1)
q = Q()
q.query["name"] = r
print(Sample.objects.filter(q))
# [<Sample: omid.raha>]
print(Sample.objects.filter(q, family='raha'))
# raise `TypeError: cannot deepcopy this pattern object`
Also, main report is available in this issue .
Try to use this instead:
q.query["name__contains"] = "omid"
Guys, is it any progress with this issue?
Guys, is it any progress with this issue?