简体   繁体   English

ndb 云数据存储写入默认命名空间

[英]ndb cloud datastore writes to default namespace

When trying to upgrade from python2 to python3, there was an issue with writing data to different namespaces.尝试从 python2 升级到 python3 时,将数据写入不同的命名空间时出现问题。

The code was writing to correct namespaces until 14 May, 2020. After that, when trying to write to a specific namespace, it writes to default namespace.代码一直写入正确的命名空间,直到 2020 年 5 月 14 日。之后,当尝试写入特定命名空间时,它会写入默认命名空间。 How can this be solved?如何解决?

from google.cloud import ndb
client = ndb.Client()

class ActiveTokens(ndb.Model):
    _memcache_timeout = 60
    namespace = user_namespace
    username = ndb.StringProperty(required=True, indexed=True)
    token = ndb.StringProperty(required=True, indexed=True)
    expiry = ndb.IntegerProperty(required=True)
    otp = ndb.IntegerProperty(indexed=True)
    created = ndb.DateTimeProperty(auto_now_add=True, required=True, indexed=True)
    edited = ndb.DateTimeProperty(auto_now=True, required=True)

    @classmethod
    def store(cls, username, token, expiry, otp):
        with client.context():
            obj = ActiveTokens(username=username,
                                    token=token,
                                    expiry=expiry,
                                    otp=otp,
                                    namespace='user'
                                    )
            return obj.put().id()

I started encountering this issue this morning when deploying my instance to the cloud.我今天早上将我的实例部署到云时开始遇到这个问题。 It was not occurring on my development environment.它没有发生在我的开发环境中。 My entities were saving under [default] namespace despite setting it in the model. I resolved this issue by downgrading google-cloud-ndb from version "1.2.1" to version "1.1.2".尽管在 model 中设置了我的实体,但我的实体仍在 [default] 命名空间下保存。我通过将 google-cloud-ndb 从版本“1.2.1”降级到版本“1.1.2”解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM