DatabaseClassSet.get should return None when id not present
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Launchpad itself |
Triaged
|
Low
|
Unassigned |
Bug Description
I've found at least 4 patterns for what the common SomeDatabaseObj
1. nothing special, and thus raise SQLObjectNotFou
2. catch SQLObjectNotFou
3. return None.
4. ape the dictionary .get() method and return an optional second argument that defaults to None.
This seems a bit of a mess.
While 4 seems the most flexible, I think it's actually wasted effort: if you're after the database row with a particular id, it seems very unlikely that some other (non-None) object will do, and in my grepping I found exactly no code taking advantage of the flexibility of these methods (not even tests). Option 1 has clear disadvantages (exposing implementation details) and so the choice is between 2 and 3.
Steve asked for 3.
Changed in launchpad: | |
status: | New → Confirmed |
description: | updated |
Changed in launchpad: | |
assignee: | nobody → jtv |
Changed in launchpad-foundations: | |
assignee: | Jeroen T. Vermeulen (jtv) → nobody |
Changed in launchpad-foundations: | |
status: | Confirmed → Triaged |
importance: | Undecided → Low |
We should be returning None.
This makes the code that typically uses these methods simpler, for example web application navigation code.