the*_*osp 9 python google-app-engine
请帮我理解这个:
在v1.6.6上,它位于第2744行google/appengine/ext/db/__init__.py:
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)
.
.
.
Run Code Online (Sandbox Code Playgroud)
在他们将索引参数约束为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)
Run Code Online (Sandbox Code Playgroud)
[1] http://code.google.com/p/googleappengine/source/browse/trunk/python/RELEASE_NOTES#1165
| 归档时间: |
|
| 查看次数: |
384 次 |
| 最近记录: |