Merge lp:~james-w/launchpad/export-code-import into lp:launchpad
Proposed by
James Westby
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Gary Poster | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~james-w/launchpad/export-code-import | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
76 lines (+44/-0) 3 files modified
lib/canonical/launchpad/doc/webservice-marshallers.txt (+16/-0) lib/canonical/launchpad/webapp/marshallers.py (+21/-0) lib/canonical/launchpad/zcml/webservice.zcml (+7/-0) |
||||
To merge this branch: | bzr merge lp:~james-w/launchpad/export-code-import | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster (community) | Approve | ||
Review via email:
|
Commit message
Exporting an IChoice based on an SQL vocabulary will now error rather than silently doing the wrong thing.
Description of the change
Hi,
This fixes the root cause of repeated problems with
exporting IChoices for them not to be available over the
API.
Thanks,
James
To post a comment you must log in.
Thank you very much for the fix and the changes.
merge-conditional on adding the comment as we discussed.
And now, I present the IRC log.
gary_poster: james_w: Did you consider AssertionError over ValueError? I was gung ho for AssertionError, but then started convincing myself of ValueError. I still lean towards AssertionError. ..ooh, no I have an idea I like better, maybe. One sec, looking up. Error, and queryMultiAdapter will return None or the provided default. Error (what I was considering) is not appropriate here because that's the responsibility of something higher up. And the reason we are doing this is to help the user figure out what they did wrong. In would be nice if the zope machinery had a spelling for that, but it doesn't. pError is the right error, if we get one at all). haller class to something like this: rError( field, request, vocabulary): laryBase- based vocabulary.
[2:55pm] james_w: I don't really mind what the error type is
[3:05pm] gary_poster: OK, james_w, here is the trivia I'm struggling with. Normally, the right thing to do in this case is to write a function (I'm going to suggest that we switch the class to a function anyway) that returns None. That behaves properly with standard Zope calls: getMultiAdapter will raise a ComponentLookup
[3:05pm] gary_poster: By explicitly raising an exception we're breaking the pattern. Raising ComponentLookup
[3:05pm] gary_poster: So, I think an AssertionError is the right thing to do for our intentions: we're doing this to help a poor developer debug and fix their problems, which is the domain of an AssertionError. A ValueError is an attempt to raise a "real" error, and would be the wrong "real" error (ComponentLooku
[3:05pm] gary_poster: So with all that, I would suggest changing the ChoiceErrorMars
[3:05pm] gary_poster: def choiceMarshalle
[3:05pm] gary_poster: # We don't support marshalling a normal Choice field with a
[3:05pm] gary_poster: # SQLObjectVocabu
[3:05pm] gary_poster: # Normally for this kind of use case, one returns None and
[3:05pm] gary_poster: # lets the Zope machinery alert the user that the lookup has gone wrong.
[3:05pm] gary_poster: # However, we want to be more helpful, so we make an assertion,
[3:05pm] gary_poster: # with a comment on how to make things better.
[3:05pm] gary_poster: assert False, (...your message...)
[3:06pm] james_w: ok
[3:06pm] gary_poster: james_w: other than that, r=gary. You cool with that?
[3:07pm] james_w: yeah, let me make the changes so that you can confirm
[3:07pm] gary_poster: ok cool
[3:07pm] lantash3 joined the chat room.
[3:11pm] danilos joined the chat room.
[3:12pm] deryck left the chat room. (Quit: Leaving)
[3:15pm] james_w: gary_poster: please re-check
[3:15pm] gary_poster: ack james_w
[3:16pm] lantash left the chat room. (Quit: Leaving.)
[3:17pm] gary_poster: james_w: +1. I really would like (something like) the comment I gave to be there too. People who know the Zope pattern will appreciate reading what's going on (like me, when I've forgotten all about this!)
[3:17pm] james_w: oh
[3:18pm] gary_poster: Other than that, that's what I had in mind. I need to step out to the bank. Would ...