From: Luke O. <lu...@me...> - 2003-05-17 22:38:57
|
Hi - Interface question for everyone to ponder: If you have a foreignKey column, or a join, and have an object with an invalid ID in one of these slots, it will raise an SQLObjectNotFound exception when you try to access any of these attributes. Which is cool and all, except that this means that many attribute accesses need to be try/excepted, instead of just the explicit creation of objects. For instance, the contrived simple access: # should be try/excepted anyways, and we do ob = Person(12) # these don't seem reasonable to do so v = ob.roles w = ob.phoneNumber should be: try: ob = Person(12) except SQLObjectNotFound: fail() try: v = ob.roles except SQLObjectNotFound: v = [] try: w = ob.phoneNumber except SQLObjectNotFound: w = None Now, I'm not entirely convinced on the solution. Sometimes you want to know that you've got bad data, other times you just want to be able to go on, blindly ignoring the bad (so having SQLObject do the exception checking in those cases would be cool). (Alternatively, as I'm sure Edmund will tell me, my database should ensure integrity at all times. And he's probably right, but this still concerns me. :) So. Should SQLObject provide an option to transparently pass over bad relationships? Perhaps at the class level, perhaps at the instance level (creation argument or anytime flag?), or should this be rethought into a stronger enforcement of relationships throughout? (We've occasionally been having full interpreter hangs on these accesses, but I haven't tracked it down, may be an odd Webware or Postgres interaction. It is completely tangential to this idea, but if anyone else is experiencing hangs instead of exceptions when accessing invalid join or FK attrs, I'd love to hear about it to help track this down.) Thanks for your thoughts, - Luke |