Python 应用程序引擎&x27;s UnindexedProperty包含奇怪的代码
请帮助我理解这一点: 在v1.6.6上,它位于google/appengine/ext/db/_uuinit_uu.py的第2744行:Python 应用程序引擎&x27;s UnindexedProperty包含奇怪的代码,python,google-app-engine,Python,Google App Engine,请帮助我理解这一点: 在v1.6.6上,它位于google/appengine/ext/db/_uuinit_uu.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 _
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之前,您可以对任何属性类型进行过滤查询,甚至是文本和Blob。他们只返回空列表,但它起作用了。版本1.2.2引入了属性的
索引
属性,允许您禁用对选定属性的索引[1]。此后,必须对要查询的属性编制索引,否则它将引发异常
我们知道文本和Blob属性不能被索引。如果不改变任何其他内容,对这些属性的查询将引发1.2.2版本的异常(以前没有)。为了不引入回归和破坏现有应用程序,将行kwds['index']=True
添加到unindex属性
类中
如果我们能够控制所有依赖的代码,那么开始引发异常将是一个更干净的解决方案。但鉴于不破坏现有应用程序,决定对其进行修补
您可以通过将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] 因此,UnindexedProperty只是强制代码不设置
indexed=True
,而是在(非文本/Blob)属性上建立索引?(与@alpert的描述匹配的示例是aetycoon中的ArrayProperty:)@BenAlpert,是的,但不应该。我提交了一个bug来解决这个问题。感谢您启动此代码考古课程。FWIW,实际检查在这里完成:@kamens谢谢你的赏金+500,这个问题可能真的让你很困扰:)我不能相信,@alpert提供了赏金。。。