Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Engine's UnindexedProperty contains strange code

Please help me understand this:

On v1.6.6 it's in line 2744 of 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)
 .
 .
 .

After they constrained the indexed parameter to be False - They set it to True!

like image 789
theosp Avatar asked Jun 04 '12 15:06

theosp


1 Answers

Before 1.2.2, you could do filter queries for any property type, even Text and Blob. They did only return empty lists, but it worked. Version 1.2.2 introduced the indexed attribute for properties which allows you to disable indexing of selected properties[1]. Since then, the property you want to query on must be indexed or it will throw an exception.

We know that Text and Blob properties can not be indexed. Not changing anything else, queries on those properties would be raising exceptions from 1.2.2 on (which they didn't before). In order to not introduce a regression and break existing apps, the line kwds['indexed'] = True was added to the UnindexedProperty class.

If we would have control over all the depending code, it would have been a cleaner solution to start raising an exception. But in the light of not breaking existing apps, it was decided to patch it.

You can try it yourself by changing kwds['indexed'] = True to kwds['indexed'] = False and run this snippet:

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

like image 58
schuppe Avatar answered Sep 25 '22 00:09

schuppe