archive.checkUpload() throws exception rather than returning False

Bug #667183 reported by Stefano Rivera
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Triaged
Low
Unassigned

Bug Description

archive.checkUpload() throws an HTTP exception rather than returning False. This is presumably by design, but painful for launchpadlib use. Having a function with a boolean response is preferable to having to use try...except.

isSourceUploadAllowed() returns boolean, but only for explicit permissions, not for general component-wide permissions (even though its name implies general permission)

Gary Poster (gary)
affects: launchpadlib → launchpad-foundations
Changed in launchpad-foundations:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Julian Edwards (julian-edwards) wrote :

checkUpload() raises an exception so that you can have more info about why the upload is not allowed. This is more useful than a simple "False".

Gary, can it doing anything different to be friendlier to the webservice?

Changed in soyuz:
status: New → Incomplete
Revision history for this message
Gary Poster (gary) wrote :

That sounds like a fair reason as to why an exception was used, even simply from a Pythonic perspective, irrespective of webservice involvement. Is the webservice allowing the error message through? We do have a mechanism to allow that.

The only other thought I have is perhaps exporting two APIs, ``checkUpload`` with the current behavior and ``canUpload`` with the requested behavior. That said, someone annoyed by the ``checkUpload`` behavior could simply wrap it with a helper function for what I proposed for the ``canUpload`` behavior, and move on. If I had to choose one of those two behaviors from the webservice itself, I'd choose the current one.

I'll ask Leonard and/or Benji to weigh in, in case they have any other ideas.

Revision history for this message
Stefano Rivera (stefanor) wrote : Re: [Bug 667183] Re: archive.checkUpload() throws exception rather than returning False

> The only other thought I have is perhaps exporting two APIs,
> ``checkUpload`` with the current behavior and ``canUpload`` with the
> requested behavior. That said, someone annoyed by the ``checkUpload``
> behavior could simply wrap it with a helper function for what I proposed
> for the ``canUpload`` behavior, and move on.

That's what I was expecting (and what we already doing in
ubuntu-dev-tools, which has all sorts of launchpadlib wrapping)

Yeah, the only issues with it are that it's not Pythonic, and that the
documentation says nothing about throwing exceptions instead of
returning something.

SR

--
Stefano Rivera
  http://tumbleweed.org.za/
  H: +27 21 465 6908 C: +27 72 419 8559 UCT: x3127

Revision history for this message
Leonard Richardson (leonardr) wrote :

checkUpload/canUpload would be fine. The current behavior is also fine, if documented properly. (quality of +apidoc documentation is definitely a huge shortcoming for us right now)

There's a network boundary between the client and the server, so there's always going to be some un-Pythonic behavior. We've tried to minimize this by mapping 2xx-3xx error codes onto normal Python object operations, and 4xx-5xx error codes onto Python exceptions, but some stuff will still not make sense.

Revision history for this message
Julian Edwards (julian-edwards) wrote : Re: [Bug 667183] Re: archive.checkUpload() throws exceptionrather than returningFalse

On Wednesday 27 October 2010 15:48:53 you wrote:
> > The only other thought I have is perhaps exporting two APIs,
> > ``checkUpload`` with the current behavior and ``canUpload`` with the
> > requested behavior. That said, someone annoyed by the ``checkUpload``
> > behavior could simply wrap it with a helper function for what I proposed
> > for the ``canUpload`` behavior, and move on.
>
> That's what I was expecting (and what we already doing in
> ubuntu-dev-tools, which has all sorts of launchpadlib wrapping)
>
> Yeah, the only issues with it are that it's not Pythonic, and that the
> documentation says nothing about throwing exceptions instead of
> returning something.

Right, the documentation is bad, I will update that.

The checkUpload() itself is wrapping something that doesn't raise exceptions.
We can expose that to return True or False if it helps.

Changed in soyuz:
status: Incomplete → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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