|
| 1 | +import weakref |
1 | 2 | from copy import deepcopy |
2 | 3 |
|
3 | 4 | import pytest |
@@ -62,6 +63,36 @@ class MyFailingDoc(Document): |
62 | 63 | class MyFailingdoc2(Document): |
63 | 64 | emb = EmbeddedDocumentField("MyDoc") |
64 | 65 |
|
| 66 | + def test_embedded_document_list_field__has__instance_weakref(self): |
| 67 | + class Comment(EmbeddedDocument): |
| 68 | + content = StringField() |
| 69 | + |
| 70 | + class Post(Document): |
| 71 | + title = StringField() |
| 72 | + comment = EmbeddedDocumentField(Comment) |
| 73 | + comments = EmbeddedDocumentListField(Comment) |
| 74 | + comments2 = ListField(EmbeddedDocumentField(Comment)) |
| 75 | + |
| 76 | + Post.drop_collection() |
| 77 | + |
| 78 | + for i in range(5): |
| 79 | + Post( |
| 80 | + title=f"{i}", |
| 81 | + comment=Comment(content=f"{i}"), |
| 82 | + comments=[Comment(content=f"{i}")], |
| 83 | + comments2=[Comment(content=f"{i}")], |
| 84 | + ).save() |
| 85 | + |
| 86 | + posts = list(Post.objects) |
| 87 | + for post in posts: |
| 88 | + assert isinstance(post.comments._instance, weakref.ProxyTypes) |
| 89 | + assert isinstance(post.comments2._instance, weakref.ProxyTypes) |
| 90 | + assert isinstance(post.comment._instance, weakref.ProxyTypes) |
| 91 | + for comment in post.comments: |
| 92 | + assert isinstance(comment._instance, weakref.ProxyTypes) |
| 93 | + for comment2 in post.comments2: |
| 94 | + assert isinstance(comment2._instance, weakref.ProxyTypes) |
| 95 | + |
65 | 96 | def test_embedded_document_field_validate_subclass(self): |
66 | 97 | class BaseItem(EmbeddedDocument): |
67 | 98 | f = IntField() |
|
0 commit comments