NameMapper issues with Google App Engine db.Model objects
Chad George <[email protected]> Sat, 14 Aug 2010 14:30:46 -0400
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
In AppEngine, db.Model objects unfortunately implement a "has_key()" method that checks if a model instance has had a key assigned to it yet. This causes NameMapper.py to determine that it should use dictionary style access instead of getattr(). I think there are two possible solutions: 1. use hasattr(obj, "keys") instead of hasattr(obj, "has_key") 2. try to use hasattr()/getattr() ... before trying dictionary access I tested #1 and it seems to work...but I'm too new to Cheetah to know if there are unintended consequences For #2 the biggest issue I see is in _valueForName() ... you definitely don't want to hit the exception on every access to a dictionary, so you'd need another call to hasattr() ... which presumably was just done before getting to _valueForName() in the first place. Probably not a big deal either way. I'm not sure if there was a pre-existing design decision to try dictionary access before attribute access. - Chad ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev