google-app-engine - 为什么 webapp2 身份验证模型使用唯一表?

标签 google-app-engine webapp2

我正在我的代码库中实现 webapp2 身份验证,并想了解这个怪癖:

models.py ,我看到它指出:

To ensure property uniqueness when creating a new User, we first create Unique records for those properties, and if everything goes well we can save the new User record::

对我来说,这似乎是一种非常复杂的测试唯一性的方法,老实说,我不完全理解“create_multi”函数在做什么....这可能就是为什么我在这里有点困惑.我的思考过程是:

Just do a quick query to see if the username (auth.id) exists in the datastore. If not then put().

我知道我遗漏了什么,有人可以向我解释一下吗?我有一种预感,也许代码是在那里输入的,这样如果人们愿意,就可以很容易地拥有多个唯一值?

谢谢!

附注显然 webapp2 代码的灵感来自 this piece of coding .

最佳答案

我们在该模型中有两个唯一值:username 和 auth_id。

因此,由于所有用户不属于同一个实体组,我们无法使用事务来检查唯一性。这就是 Unique 模型存在的原因:确保这两个属性的唯一性。

我同意,这很复杂。但是你还会怎么做呢? (诚​​实的问题)

更新:关于为何以这种方式检查唯一性的更多详细信息。

只有两种方法可以(安全地)执行数据存储的唯一约束:事务处理或使用实体键。交易仅限于最多 5 个实体组,并且使用 key ,您仅限于 1 个唯一属性。如果不想使用 key (因为,比如说,属性可以是可变的,就像电子邮件一样),或者您真的需要更多独特的属性 同类,您需要创建一个专门用于唯一性检查的类型。您发布的链接中或多或少做了什么。

关于google-app-engine - 为什么 webapp2 身份验证模型使用唯一表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9716542/

相关文章:

swift - 我如何将完美(快速)后端代码 + PostgreSQL 部署到 Google App Engine

google-app-engine - CSS 文件未在部署时更新(Google AppEngine)

python - 如何在 webapp2 中使用 User 对象的 Expando 属性?

python - 更改|为 Google App Engine Datastore 上的模型实例分配父级

python - GAE Python - 操作错误 : (2013, 'Lost connection to MySQL server during query')

python - Webapp2导入错误: cannot import name _thread

java - Spring @ComponentScan 不适用于 @Repository

python - 在 python webapp2 中如何将 __init__ 放入处理程序中(用于获取和发布)

google-app-engine - 应用引擎 : restrictions on the Datastore Entities `kind` value?

python - 如何通过 params webapp2 python 发送字典?