1
votes

I'm having a strange issue in the Google App Engine SDK v1.8.2.1. The SDK seems to have an issue with the way I retrieve a property value. The entity look like so:

class userDB(EndpointsModel):
    userID = ndb.StringProperty(required=True, indexed=True)
    name = ndb.StringProperty(required=True, indexed=True)
    update = ndb.DateTimeProperty(indexed=True)
    orgs = ndb.StructuredProperty(providers, repeated=True, indexed=True)
    system = ndb.StructuredProperty(system, repeated=True, indexed=True)
    comp = ndb.StructuredProperty(comp, repeated=True, indexed=True)

From the datastore viewer:

orgs.value (list) [u'comp', u'system']

My cron job code:

class CronRefresh(webapp2.RequestHandler):
    def get(self):  
        for user in userDB.query().fetch():
            for org in user.orgs:
                provider.addItems(user.key, org.value)

When I print org.value to console log there is no problem but when I try to pass it to the function it throws the following error.

INFO     2013-07-29 17:28:30,980 module.py:595] default: "POST / HTTP/1.1" 200 594
ERROR    2013-07-29 21:28:37,374 webapp2.py:1552] '_BaseValue' object has no attribute 'value'

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__

    return handler.dispatch()

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch

    return self.handle_exception(e, self.app.debug)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch

    return method(*args, **kwargs)

  File "E:\main.py", line 74, in get

    provider.addItems(user.key, org.value)

AttributeError: '_BaseValue' object has no attribute 'value'

INFO     2013-07-29 17:28:37,382 module.py:595] default: "GET /cron/refresh HTTP/1.1" 500 114
INFO     2013-07-29 17:28:49,043 module.py:595] default: "GET /cron/refresh HTTP/1.1" 200 -

But if I run the cron job twice it will go through fine. Does anyone see what I'm doing wrong? is this expected behavior?

UPDATE: provider is an import I wrote. Any help would be much appreciated.

UPDATE2: Added the addItems function. I have confirmed that apple_list is a proper list of dictionaries.

def addItems(key, X):
user = key.get()
if X == 'apple':
    def add(item):
        newObject = apple(name=item['name'], status=item['status'], obtained=item['obtained'])
        objectList = user.query().fetch()[0].apple
        for object in objectList: 
            if (object.name == item['name'] and (object.status != item['status'] or object.obtained != item['obtained'])):
                logging.debug("If #1 Happened")
                continue
            elif (object.name == item['name'] and object.status == item['status'] and object.obtained == item['obtained']):
                logging.debug("If #2 Happened")
                continue
            else:
                logging.debug("Else Happened")
                continue

    if not user.query().fetch()[0].apple:
        for item in apple_list:
            user.apple.append(apple(name=item['name'], status=item['status'], obtained=item['obtained']))
            user.put()
    else:
        for item in apple_list:
            add(item)
1
Where is provider defined? - Brent Washburne
provider is an import I wrote that hosts the function addItems - Jeff
I saw your other posting that shows provider inherits from EndpointsModel. There's no way for us to guess what else is not included here. Your question has too little information for us to help you, so I'm marking it down. - Brent Washburne
The naming convention probably isn't the best but providers is an EndpointsModel that you see in my other post. While provider is a "module" that I wrote. It also doesn't make sense that sometimes my code works err gets past the first call to an entity property but fails in subsequent calls within the addItems function with the same _BaseValue error. For more detail, I've added the addItems funtion for the rest of the applicable code. Would it really be my code if it works when printing to the console log? I'm leaning toward what you pointed out about the .put() call. Any help? - Jeff
The problem isn't with addItems(), it's with org.value. There must be something else affecting user.orgs that is not shown here. - Brent Washburne

1 Answers

1
votes

Apparently, user.orgs has been put() to the database. That "mutates" it into a _BaseValue, as described here: List items from repeated StringProperty get mutated to _BaseValue on put.