App Engine 1.8.4 raises AttributeError putting document into search index

276 views Asked by At

I'd been using the 1.8.1 version of the App Engine API due to a known issue with the remote API in a later version. Trying the latest 1.8.4, I'm encountering an error with code that was working fine in 1.8.1 but now fails trying to add a document to a search index:

Traceback (most recent call last):
   File "~/tools/devappserver2/api_server.py", 
62, in _handle_POST
    api_response = _execute_request(request).Encode()
  File "~/tools/devappserver2/api_server.py", line 1
23, in _execute_request
    make_request()
  File "~/tools/devappserver2/api_server.py", line 1
15, in make_request
    request_id)
  File "~/google/appengine/api/apiproxy_stub.py", line 130, in MakeSy
ncCall
    method(request, response)
  File "~/google/appengine/api/search/simple_search_stub.py", line 65
4, in _Dynamic_IndexDocument
    index.IndexDocuments(params.document_list(), response)
  File "~/google/appengine/api/search/simple_search_stub.py", line 40
4, in IndexDocuments
    self._inverted_index.AddDocument(doc_id, document)
  File "~/google/appengine/api/search/simple_search_stub.py", line 30
3, in AddDocument
    self._AddFieldType(field.name(), field.value().type())
  File "~/google/appengine/api/search/simple_search_stub.py", line 28
9, in _AddFieldType
    self._schema.AddFieldType(name, field_type)
AttributeError: 'dict' object has no attribute 'AddFieldType'

ERROR    2013-09-14 22:31:45,132 webapp2.py:1552] AttributeError("'dict' object has no attribute 'Ad
dFieldType'",)
Traceback (most recent call last):
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispat
cher
    return route.handler_adapter(request, response)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "~/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "~/docroot/update.py", line 49, in get
    booking.add_to_search_index()
  File "~/docroot/booking.py", line 94, in add_to_search_index
    index.put(booking_full_text_document)
  File "~/google/appengine/api/search/search.py", line 2506, in put
    response)
  File "~/google/appengine/api/apiproxy_stub_map.py", line 94, in Mak
eSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "~/google/appengine/api/apiproxy_stub_map.py", line 328, in Ma
keSyncCall
    rpc.CheckSuccess()
  File "~/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitIm
pl
    self.request, self.response)
  File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
00, in MakeSyncCall
    self._MakeRealSyncCall(service, call, request, response)
  File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
34, in _MakeRealSyncCall
    raise pickle.loads(response_pb.exception())
RuntimeError: AttributeError("'dict' object has no attribute 'AddFieldType'",)
INFO     2013-09-14 22:31:45,145 module.py:593] default: "GET /update/somekey/someparamter/value HTTP/1.1" 500 2
691

The section of code responsible:

from google.appengine.ext import ndb
from google.appengine.api import search
import logging

class Booking(ndb.Model):

    timestamp = ndb.DateTimeProperty(auto_now_add=True)
    last_modified = ndb.DateTimeProperty(auto_now=True)

    field1 = ndb.StringProperty()
    field2 = ndb.StringProperty()
    #etc...

    def add_to_search_index(self):

        list_of_full_text_fields = [
            'field1',
            'field2',
        ]

        full_text_data = []

        for field in list_of_full_text_fields:

            full_text_data.append(unicode(getattr(self, field)))

        full_text_data = ' '.join(full_text_data)

        full_text_document = search.Document(

        doc_id = self.key.urlsafe(),
        fields=[
            search.TextField(
                name='f',
                value=full_text_data
            ),
           ]
        )

        try:
            index = search.Index(name="fullText")
            index.put(full_text_document)
        except search.Error:
            logging.exception('Put failed')
1

There are 1 answers

0
lecstor On BEST ANSWER

Could it be the API changes in those versions?

Version 1.8.3 - August 6, 2013 Published a major rewrite of the Search API documentation. Please see: https://developers.google.com/appengine/docs/python/search/

or the bugfix..

Version 1.8.4 - September 9, 2013 Fixed a unicode issue associated with expressions in the Search API. A search with snippeted fields was failing on documents containing unicode characters.

http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes