Problem posting to datastore with deferred.defer tasks
Question: I am trying to do this on Google App Engine in Python:

    
    
    def add_to_db(person):
         a = PersonDb(key_name = person)
         # get some data
         data1 = a.name
         data2 = a.age
         a.put()
    
    for person in people:
        deferred.defer(add_to_db, person, _queue="myque")
    

When I run the above code via a cron job it does not work. The file executes
without error, The tasks (there are 200 strings in list 'People') get added to
the queue correctly and trickle through correctly. But the database PersonDb
does not get updated. I know the function works (the above is simplified)
because this works:

    
    
    for person in people:
         add_to_db(person)
    

The above 2 lines of code works, and the database gets updated, but I need to
run this as a deferred task. Any suggestions?

**UPDATE** : I am getting this in the log: File "C:\Program
Files\Google\google_appengine\google\appengine\ext\deferred\deferred.py", line
129, in run raise PermanentTaskFailure(e) PermanentTaskFailure: 'module'
object has no attribute 'add_to_db'


Answer: This is probably happening because the function you are trying to defer
(`add_to_db`) is defined in the request handler. Move `add_to_db` to another
module (a different python file) and import it from there (`from myfuncs
import add_to_db`).

This limitation is mentioned in the limitations section of the deferred
[article](http://code.google.com/appengine/articles/deferred.html).

