gpt4 book ai didi

python - 保存 django mongoengine 模型实例时无效的 EmbeddedDocumentField 项(保存()失败)

转载 作者:可可西里 更新时间:2023-11-01 10:34:02 27 4
gpt4 key购买 nike

我正在尝试保存模型的实例,但我得到了

Invalid EmbeddedDocumentField item (1)

其中 1 是项目的 ID(我认为)。

模型定义为

class Graph(Document):
user = StringField(max_length=50, required=True)
title = StringField(max_length=500)
description = StringField(max_length=1000)
# field in error
graph_nodes = ListField(EmbeddedDocumentField(Graph_Node))
procedure = ListField(DictField())
created_on = DateTimeField(default=datetime.datetime.now)

def __unicode__(self):
return self.title

meta = {
'ordering': ['-created_on'],
'allow_inheritance': False,
}


class Graph_Node(EmbeddedDocument):
id = StringField(required=True, max_length=30)
button = StringField(max_length=40, required=True)
parameter = StringField(max_length=50, required=False)
values = ListField(StringField(max_length=30, required=False))
wires_out = ListField(StringField(max_length=30, required=False))
wires_in = ListField(StringField(max_length=30, required=False))

def __unicode__(self):
return self.id

meta = {
'allow_inheritance': False
}

def fill(self, args):
for k in args.keys():
if k in self.__dict__['_data'].keys():
self.__dict__['_data'][k] = args[k]

调用 save() 方法如下:

Graph(user=request.user.username, title=title, 
description=description, procedure=procedura,
graph_nodes=gnlist).save()

异常在保存时抛出,而不是在图创建时抛出。

gnlist 是(来自 pydev 调试器)

list: [<Graph_Node: start>, <Graph_Node: 1>, <Graph_Node: end>]

gnlist[1] 似乎格式正确(如果需要我会发布更多细节)

我试图在 mongodb 上跟踪查询,但它似乎没有被分析,但是输出如下(以防帮助我从不相关的日志中清除它):

{ "ts" : ISODate("2012-10-26T18:25:07.492Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(248), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(2), "w" : NumberLong(4) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:26:07.505Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(680), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:26:25.803Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 2, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(62), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(7), "w" : NumberLong(3) } }, "nreturned" : 2, "responseLength" : 758, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:27:07.506Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(698), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(6), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:27:18.817Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 4, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(121), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(11), "w" : NumberLong(8) } }, "nreturned" : 4, "responseLength" : 1463, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:02.570Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 5, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(112), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(13), "w" : NumberLong(7) } }, "nreturned" : 5, "responseLength" : 1799, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:07.507Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(680), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(5), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:11.608Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 7, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(117), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(10), "w" : NumberLong(7) } }, "nreturned" : 7, "responseLength" : 2504, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:51.589Z"), "op" : "command", "ns" : "analysis.$cmd", "command" : { "profile" : 0 }, "ntoreturn" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(0), "w" : NumberLong(24) }, "timeAcquiringMicros" : { "r" : NumberLong(0), "w" : NumberLong(11) } }, "responseLength" : 58, "millis" : 0, "client" : "127.0.0.1", "user" : "" }

谢谢

最佳答案

看来已经解决了:

我找到了 this issue .

我安装了 mongoengine 的新稳定版本:0.6.2

重启后 mongoengine 告诉我问题出在哪里:

values 属性太短,无法保存文件路径,所以我更改了

values = ListField(StringField(max_length=30, required=False))

values = ListField(StringField(max_length=100, required=False))

感谢大家

关于python - 保存 django mongoengine 模型实例时无效的 EmbeddedDocumentField 项(保存()失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13091852/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com