Collection dictionary access incorrectly folds all HTTP errors to KeyError

Bug #626960 reported by Māris Fogels
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Ubuntu Distributed Development
Invalid
High
Martin Pool
lazr.restfulclient
Fix Released
High
Martin Pool

Bug Description

When accessing a collection as a dictionary, if the server is not available, then the collection will raise a KeyError. This makes programming errors (misspelled key names) impossible to tell apart from network issues.

When doing dictionary-like access on a collection, all server errors should raise a ServerError exception.

As a workaround, one can force ServerError to be raised by replacing dictionary-like access with method access:

    >>> lp.project_groups['launchpad-project'].projects

    becomes

    >>> lp.project_groups('launchpad-project').projects

Related branches

Revision history for this message
Gary Poster (gary) wrote :

I agree. I'll add this to the list of usability issues to consider soon.

affects: lazr.restful → lazr.restfulclient
Changed in lazr.restfulclient:
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Martin Pool (mbp) wrote :

We hit this in the udd importer as bug 827263.

This is more than a usability error because it's actually incorrect, not just unhelpful, to say the object doesn't exist when it does.

You can also reach this if eg the token has expired.

summary: - Collection dictionary access should not return KeyError when the server
- is down
+ Collection dictionary access incorrectly folds all HTTP errors to
+ KeyError
Revision history for this message
Martin Pool (mbp) wrote :

This probably accounts for exult, and possibly other things that failed in a restfulclient __getentry__. Requeuing them will possibly fix it (if the error was a transient error.)

Changed in lazr.restfulclient:
assignee: nobody → Martin Pool (mbp)
importance: Medium → High
status: Triaged → In Progress
Changed in udd:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Martin Pool (mbp)
Revision history for this message
Martin Pool (mbp) wrote :

this is merged to trunk of restfulclient; thanks for the speedy review gmb.

I think this doesn't need any specific changes in udd, and it would not be worth adding a workaround. We should make a release of restfulclient and then get that backported and deployed.

Changed in lazr.restfulclient:
status: In Progress → Fix Committed
Martin Pool (mbp)
Changed in lazr.restfulclient:
milestone: none → 0.11.3
Revision history for this message
Martin Pool (mbp) wrote :

i'm closing the udd task because nothing needs to change in udd itself; but it would be really good to finish and deploy a new lazr.restfulclient package.

Changed in udd:
status: In Progress → Invalid
Changed in lazr.restfulclient:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.