在ndb的异步操作中如何确定'auto_now_add'的值? [英] How is the value of 'auto_now_add' determined in ndb's async operation?

查看:107
本文介绍了在ndb的异步操作中如何确定'auto_now_add'的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据ndb文档,当创建实体时, auto_now_add 会将属性设置为当前日期/时间。

我想知道在异步操作中值是如何确定的 - 即,它是由创建内存模型对象的时间决定的,还是由模型实际写入数据存储的时间确定的?

解决方案

文档说直到实体写入才会生成自动值;也就是说,这些选项不提供动态默认值。 )注意:使用auto_now_add = True写入属性的事务失败并且稍后重试时,它将重新使用相同的时间值就像原来的尝试,而不是将其更新到重试时间一样,如果事务永久失败,则该属性的值仍将设置在实体的内存副本中。


According to the ndb doc, auto_now_add would set property to current date/time when entity is created.

I would like to know how the value is determined in async ops - i.e., Is it determined by the time when an in-memory model object is created, or by the time when the model is actually written to datastore?

解决方案

The docs say " The automatic value is not generated until the entity is written; that is, these options don't provide dynamic defaults. (These details differ from the old db API.)

Note: When a transaction writing a property with auto_now_add=True fails and is later retried, it will reuse the same time value as on the original try rather than update it to the time of the retry. If the transaction fails permanently, the property's value will still be set in the in-memory copy of the entity."

这篇关于在ndb的异步操作中如何确定'auto_now_add'的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆