From: Luke O. <lu...@me...> - 2003-04-18 20:58:20
|
Not sure if i just saw a message about this, but can't find it.. modification to _SO_fetchAlternateID to deal with the situation where there is no record with that value. def _SO_fetchAlternateID(cls, dbIDName, value): result = cls._connection._SO_selectOneAlt( cls, [cls._idName] + [col.dbName for col in cls._columns], dbIDName, value) if not result: raise KeyError, "The object %s by the alternate ID (%s) %s does not exist" % (cls.__name__, dbIDName, value) obj = cls(result[0]) .... Now, this raise the question of what error to raise. We're doing a similar check in _init() if the ID is non-existent, and KeyError isn't exactly the right error to throw for these "no such object exists". We're catching a generic LookupError for now for both these cases, but I suggesting an SQLObject-specific lookup error: class SQLObjectLookupError(LookupError): pass (or maybe named NoSuchObject(LookupError) ?) just so that catches can be more explicit and not catch other generic Key/Lookup Errors. Thoughts? (Think of a better name for it? I definitely think it should inherit from LookupError, and not just Exception..) - Luke |