0

概要:

私のユーザー ドキュメントは、FileFields を持つ画像ドキュメントを参照します。FileField を使用してオブジェクトをディープコピーすることはできません (なぜですか?)。したがって、ユーザー ドキュメントのディープ コピーは、関連付けられた Image (FileField を使用) を逆参照すると失敗します。


MongoEngine (0.7.8) を使用してコレクションをクエリしようとしていますが、そのようにクエリすると:

    >>> cls.objects(Q(author=devin_user))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying author works fine

    >>> cls.objects(Q(parent=strike_user))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying parent works fine

    >>> cls.objects(Q(parent=strike_user) & Q(author=devin_user))
    *** TypeError: 'Collection' object is not callable. If you meant to call the '__deepcopy__' method on a 'Collection' object it is failing because no such method exists.
    # Definitely fails here, but why?


    # Even stranger, if I combine a query on parent and hidden_at it succeeds, but if I combine a query on author and hidden_at it gloriously fails
    >>> cls.objects(Q(parent=strike_user) & Q(hidden_at=None))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying parent works fine

    >>> cls.objects(Q(author=devin_user) & Q(hidden_at=None))
    *** TypeError: 'Collection' object is not callable. If you meant to call the '__deepcopy__' method on a 'Collection' object it is failing because no such method exists.
    # Boom!

strike_user と devin_user は 2 つのユーザー ドキュメントです。Event は次のようになります (ちなみに、継承は許可されています)。

    class Event(Document):                                             
       """                                                            
       :param anti: tells if an event is related to an inverse event  
           e.g. follow/unfollow, favorite/unfavorite                  
       :param partner: relates an anti-event to an event.             
           only set on the undoing event                              
       """                                                            
       author = GenericReferenceField(required=True)                  
       parent = GenericReferenceField(required=True)                  
       created_at = DateTimeField(required=True, default=datetime.now)
       hidden_at = DateTimeField()                                    

       anti = BooleanField(default=False)                             
       partner = ReferenceField('Event', dbref=False)                 
       meta = {                                                       
           'cascade': False,                                          
           'allow_inheritance': True }

       def __repr__(self):
           action = "=/>" if self.anti else "=>"
           return "<%s: [%s %s %s]>" % (self.__class__.__name__,
               self.author.__repr__(), action, self.parent.__repr__())

私にはバグのように思えますが、フィードバックを聞くことに非常に興味があります:)


アップデート:

mongoengine/queryset.py:98 が copy.deepcopy を呼び出しているようです。これは ReferenceField に続き、その FileField データもコピーしようとします。残念ながら、これは機能しません。

    Class Image(Document):
        file = FileField(required=True)

    Class User(Document):
        name = StringField()
        image = ReferenceField('Image')

    >>> copy.deepcopy(user)
    *** TypeError: 'Collection' object is not callable. If ...

    >>> user.image = None
    >>> copy.deepcopy(user)
    <User: Devin>
4

1 に答える 1

0

結局のところ、これはバグです!概要で言ったことは正しいです。[バグの状況

便利なリンク:

バグのステータス

メーリングリストディスカッション

于 2012-12-17T19:34:27.303 に答える