hmarr/mongoengine — Issue #411: Deepcopy - regex and Q querysets
Author: rozza
Created: 2012-01-16 09:26:17+00:00
State: open

Here's what I'm trying to do. Using a regex causes "TypeError: cannot
deepcopy this pattern object"

import re
MyDocument.objects(domain='amazon.com')
if subject:
filter(subject=re.compile('.*'))

Any suggestions? I realize there are some ways around this (i.e.
build a dict and then do MyDocument.objects(**kwargs)), but I also
need to include an OR expression:

from mongoengine.queryset import Q
MyDocument.objects( (Q(subject=re.compile('text.*'))|
Q(subject=re.compile('other.*')) & Q(domain='amazon.com')))

Which seems to require a deepcopy as it throws the same error.