__setattr__ and __getattr__ causing memcacahe error in 1.8.5

60 views
Skip to first unread message

Brian Becker

unread,
Oct 1, 2013, 12:34:12 AM10/1/13
to google-a...@googlegroups.com
After upgrading to 1.8.5 (from 1.8.1) I instantly had Internal Server Error whenever my class was instantiated and placed in memcache:
  daRef = oRefFinder()
  memcache.set( 'theRef', daRef)

The last lines of the error trace says that the memcache.set command:
  File "/base/data/home/apps/s~refindservice/1.370602298270267557/main.py", line 117, in get
    memcache.set('theRef' , daRef )
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 763, in set
    namespace=namespace)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 868, in _set_with_policy
    time, '', namespace)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 947, in _set_multi_async_with_policy
    stored_value, flags = _validate_encode_value(value, self._do_pickle)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 227, in _validate_encode_value
    stored_value = do_pickle(value)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 392, in _do_pickle
    pickler.dump(value)
TypeError: 'NoneType' object is not callable


I finally traced it to __setattr__ and __getattr__. If I go into my class and change  __setattr__ and __getattr__ methods to something else like tabooset and tabooget -- Memcache error goes away. GRRRR.

If I delete all the content in my __setattr__ and just put "pass" -- it still bombs -- so this is specific to the name of those methods.

First, what is going on?
Second, is there some other way I'm supposed to be setting and getting attributes in my classes in GAE?

And yes, this was operating fine before I upgraded from 1.8.1 to 1.8.5.

Brian
 

timh

unread,
Oct 1, 2013, 1:34:22 AM10/1/13
to google-a...@googlegroups.com
You should show some code.  Are you actually overriding __settattr__ and __getattr__ in your models ?

T

Brian Becker

unread,
Oct 1, 2013, 1:51:13 AM10/1/13
to google-a...@googlegroups.com

Yes.

     def __setattr__( self, name, value ):

           if name == 'orig':

                # force value to string & kill whitespace

                value = unicode(value).strip()

               

                ###### Lots more cleaning is necessary

                # clean off ending characters

                value = value.rstrip(' ,;:)(')

                # Ps 3:1; cf. => Ps 3:1

                if value[-3:] == 'and': value = value.replace('and','')

                if value[-2:] == 'cf': value = value.replace('cf','')

                # clean off ending characters again

                value = value.rstrip(' ,;:)(')

                self.__dict__[ 'orig'] = value

--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/2d9UO1m0wV8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

timh

unread,
Oct 1, 2013, 4:08:59 AM10/1/13
to google-a...@googlegroups.com
I personally would be very careful about overriding __setattr__ given the heavly reliance on metaclasses and db/ndb property binding.
You are not even calling super on setattr and you may well be preventing some fundamental model behaviour from kicking in.

For instance your error. This also applies to overrriding __init__ on model classes.

If you insist on doing this I would be making sure you call super, rather than fiddling with internal structures yourself.

Regards

Tim Hoffman

To unsubscribe from this group and all its topics, send an email to google-appeng...@googlegroups.com.
To post to this group, send email to google-...@googlegroups.com.

timh

unread,
Oct 1, 2013, 4:34:13 AM10/1/13
to google-a...@googlegroups.com
On further though I really think you are going about this the wrong way.

You haven;'t said if you using ndb or db, if you are using ndb you should be providing a function to validator argument that will co-erce the data for you.
Alternately subclass the Property to provide the functionality you want and not override __setattr__ which as you have found out could/will cause problems
with new releases of the appengine runtime, as you are not using the public api for models/properties.

Tim

To unsubscribe from this group and all its topics, send an email to google-appeng...@googlegroups.com.
To post to this group, send email to google-...@googlegroups.com.

Brian Becker

unread,
Oct 1, 2013, 4:51:26 AM10/1/13
to google-a...@googlegroups.com

Neither, it is strictly a service which processes a string and spits back a result.

To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.

timh

unread,
Oct 1, 2013, 4:57:16 AM10/1/13
to google-a...@googlegroups.com
You are running into basic pickle problem then, 

The OP had exactly the same error as you.

T

Brian Becker

unread,
Oct 1, 2013, 6:14:53 AM10/1/13
to google-a...@googlegroups.com

I got rid of my __getattr__ and use @property for most of them. I didn’t touch the __setattr__ but memcache is working just fine now. Strange.

 

Brian

To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.

timh

unread,
Oct 1, 2013, 6:16:46 AM10/1/13
to google-a...@googlegroups.com
If you look at the SO q/a you will see the problem is with the __getattr__

T

Brian Becker

unread,
Oct 1, 2013, 10:29:50 AM10/1/13
to google-a...@googlegroups.com

Thanks for finding that thread btw, Tim.

To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages