0

I'm using the Python 1.6.6 SDK and having trouble getting the search API to initialise a new Document:

from google.appengine.api import search

def index_document(document_id, some_string):
    return search.Document(
        doc_id=document_id,
        fields=[
            search.TextField(name='text_field', value=some_string),
            search.DateField(name='date', value=datetime.now().date())
        ])

In response I get:

AttributeError: type object 'search' has no attribute 'Document'

I can't see any evidence that this is a general problem, and all the docs point to this being the procedure for initialising a Document.

However, if I place the API call within the function it executes as expected:

def index_document(document_id, some_string):

    from google.appengine.api import search

    return search.Document(...

I can't see any reason why this would work, but a global import wouldn't as I am importing a number of their APIs. Has anyone had a similar problem/success in getting it to work?

notreadbyhumans
  • 607
  • 9
  • 17
  • The global import should work fine, and nothing is obviously wrong with your code. Are you definitely using the 1.6.6. SDK? (Does the import itself give you an error?) Is there any chance that what you intend as a global import is in fact more locally scoped? – Amy U. Jun 01 '12 at 06:03
  • Doh!!! I had a webapp.RequestHandler named search! Renaming this solved the issue. – notreadbyhumans Jun 01 '12 at 08:05

1 Answers1

0

Check that you have no other objects with the same name.

notreadbyhumans
  • 607
  • 9
  • 17