来自ndb.DateTimeProperty(auto_true = now)的ndb.ComputedProperty首次调用错误

werm098

我有一个具有ndb.DateTimeProperty的ndb.Model和一个使用ndb.DateTimeProperty创建时间戳的ndb.ComputedProperty。

import time
from google.appengine.ext import ndb

class Series(ndb.Model):
    updatedDate = ndb.DateTimeProperty(auto_now=True)
    time = ndb.ComputedProperty(lambda self: time.mktime(self.updatedDate.timetuple()))

我遇到的问题是在第一次调用.put()时(seriesObj只是从Series类创建的对象)

seriesObj.put()

ndb.DateTimeProperty此时为空。我收到以下错误:

File "/main.py", line 0, in post series.put()
time = ndb.ComputedProperty(lambda self: time.mktime(self.updatedDate.timetuple()))
AttributeError: 'NoneType' object has no attribute 'timetuple'

我可以说这仅仅是因为未设置ndb.DateTimeProperty,但是在ndb.ComputedProperty去读取它之前,我不知道如何设置它。

这不是ndb.ComputedProperty的问题,因为我已经使用ndb.DateTimeProperty设置对其进行了测试,并且工作正常。

任何帮助都将是巨大的!

werm098

在进一步研究此问题后,避免在导入模块时评估默认值。我刚设置了updatedDate创建新的初始值Series

import datetime
series = Series(updatedDate = datetime.datetime.now())
series.put()

我本来希望使用更“不要考虑”的解决方案,_pre_put_hook但在测试中,它似乎在评估之前没有被调用time ComputedProperty

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

按DateTimeProperty的时间部分查询NDB

来自分类Dev

正确使用GAE ndb.ComputedProperty

来自分类Dev

使用ndb.blobproperty引起的值错误

来自分类Dev

ndb.DateTimeProperty上的Query.order不以正确的顺序返回结果

来自分类Dev

ndb单例模式

来自分类Dev

MySQL NDB API AccessViolationException

来自分类Dev

视频模型和ndb

来自分类Dev

Appengine ndb 动态选择

来自分类Dev

使用 ndb.ComputedProperty 非祖先查询确保事务更新成功

来自分类Dev

使用Google App Engine NDB的Odoo | 从Postgresql移植到NDB

来自分类Dev

在NDB模型中存储对非NDB对象的引用

来自分类Dev

如何计算NDB写入次数?

来自分类Dev

NDB中的多对多关系

来自分类Dev

Google App Engine NDB查询

来自分类Dev

NDB与父母的allocate_ids

来自分类Dev

如何更新NDB模型的架构

来自分类Dev

App Engine NDB交易冲突

来自分类Dev

ndb.GeoPt的重复StructuredProperty

来自分类Dev

NDB验证器支持字段

来自分类Dev

GAE ndb按键过滤(id)

来自分类Dev

大量NDB实体的更新失败

来自分类Dev

在NDB中获取实体密钥

来自分类Dev

NDB卖出交易被覆盖

来自分类Dev

互相引用的python ndb类

来自分类Dev

删除NDB EntitiesByProperty索引表

来自分类Dev

如何使用ndb库schemeless

来自分类Dev

如何按键删除 NDB 值

来自分类Dev

已部署 GAE NDB 安装

来自分类Dev

python的追加与ndb.StringProperty(repeated = True)一起使用吗?