mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Deepcopy - regex and Q querysets

Open omidraha opened this issue 11 years ago • 3 comments

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 .

omidraha avatar Aug 06 '14 10:08 omidraha

Try to use this instead:

q.query["name__contains"] = "omid"

DavidBord avatar Mar 27 '15 14:03 DavidBord

Guys, is it any progress with this issue?

NatalyMac avatar Sep 18 '20 15:09 NatalyMac

Guys, is it any progress with this issue?

WarBean avatar May 06 '21 17:05 WarBean