gpt4 book ai didi

python - App Engine 的未索引属性包含奇怪的代码

转载 作者:太空狗 更新时间:2023-10-29 20:28:38 27 4
gpt4 key购买 nike

请帮助我理解这一点:

在 v1.6.6 上,它位于 google/appengine/ext/db/__init__.py 的第 2744 行:

class UnindexedProperty(Property):
"""A property that isn't indexed by either built-in or composite indices.

TextProperty and BlobProperty derive from this class.
"""
def __init__(self, *args, **kwds):
"""Construct property. See the Property class for details.

Raises:
ConfigurationError if indexed=True.
"""
self._require_parameter(kwds, 'indexed', False)



kwds['indexed'] = True
super(UnindexedProperty, self).__init__(*args, **kwds)
.
.
.

在他们将索引参数限制为 False 之后 - 他们将其设置为 True!

最佳答案

在 1.2.2 之前,您可以对任何属性类型进行过滤查询,甚至是 Text 和 Blob。他们只返回空列表,但它起作用了。版本 1.2.2 为属性引入了 indexed 属性,允许您禁用选定属性的索引[1]。从那时起,您要查询的属性必须被索引,否则会抛出异常。

我们知道 Text 和 Blob 属性不能被索引。不更改任何其他内容,对这些属性的查询将从 1.2.2 开始引发异常(之前没有)。为了不引入回归和破坏现有应用程序,行 kwds['indexed'] = True 被添加到 UnindexedProperty 类。

如果我们能够控制所有相关代码,那么开始引发异常将是一个更简洁的解决方案。但考虑到不破坏现有应用程序,我们决定对其进行修补。

您可以自己尝试,将 kwds['indexed'] = True 更改为 kwds['indexed'] = False 并运行此代码段:

from google.appengine.ext import db

class TestModel(db.Model):
text = db.TextProperty()

TestModel(text='foo').put()
print TestModel.all().filter('text =', 'foo').fetch(10)

[1] http://code.google.com/p/googleappengine/source/browse/trunk/python/RELEASE_NOTES#1165

关于python - App Engine 的未索引属性包含奇怪的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10884055/

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