MongoEngine / MongoEngine/mongoengine
Error occured when disable auto dereference and use StringField regex check
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
import unittest
from mongoengine import DynamicDocument, connect
from mongoengine.fields import StringField
class User(DynamicDocument):
username = StringField(required=True)
pa_id = StringField(required=True, regex=r'(^PA\d\d\d\d$)')
class Test(unittest.TestCase):
def setUp(self) -> None:
connection = connect(db='mongotest', host='mongomock://localhost')
def test(self):
a = User(username='stonemoe', pa_id='PA0001').save()
self.assertEqual(1, User.objects.count())
# RAISE HERE: TypeError: cannot deepcopy this pattern object
for user in User.objects.no_dereference():
print(user)
if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(Test)
unittest.TextTestRunner().run(suite)
Root cause may be:
https://github.com/MongoEngine/mongoengine/blob/92f6fce77d12f930333bd8980fa611627d3a8d1b/mongoengine/base/document.py#L782-L783
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided unittest reproduction and inspect mongoengine/base/document.py around lines 782-783, where the issue identifies the possible root cause. Verify the failure when iterating over User.objects.no_dereference() with the StringField regex, then confirm that the test completes without the deepcopy TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100