Merge lp:~james-w/lazr.restful/object-unmarshal into lp:lazr.restful
Status: | Rejected |
---|---|
Rejected by: | Leonard Richardson |
Proposed branch: | lp:~james-w/lazr.restful/object-unmarshal |
Merge into: | lp:lazr.restful |
Diff against target: |
102 lines (+34/-4) 4 files modified
src/lazr/restful/docs/webservice-marshallers.txt (+20/-0) src/lazr/restful/fields.py (+6/-1) src/lazr/restful/marshallers.py (+5/-0) src/lazr/restful/tales.py (+3/-3) |
To merge this branch: | bzr merge lp:~james-w/lazr.restful/object-unmarshal |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Leonard Richardson (community) | Disapprove | ||
Gary Poster | Disapprove | ||
Review via email: mp+22182@code.launchpad.net |
Description of the change
Hi,
This is a fix to stop bugs like bug 546558 from happening again.
Launchpad defines an adapter that makes lazr.restful use
the Object marshaller for every Choice with an SQL-based vocabulary.
However, it doesn't do anything to turn those Choices in to
ReferenceChoices automatically.
tales.py in lazr.restful uses the Interface of the field to determine
whether to add _link to the name, but the Object marshaller does
it unconditionally.
Throwing the error at unmarshall time isn't pretty, but there is a
comment in tales.py that we can't do it at that point. It could be
done at marshaller creation time instead.
An alternative would be for the Object marshaller to choose whether
to append _link depending on the type as tales.py does, but that
wouldn't enforce the _link convention.
Thanks,
James
Unmerged revisions
- 127. By James Westby
-
Fix long line in the doctest. Thanks Gary.
- 126. By James Westby
-
Test that an ObjectLookupFie
ldMarshaller without an object field fails to unmarshal.
Summary of IRC conversation:
- I think that Launchpad is abusing the Object field marshaller by using it to marshall a Choice field and that LP should simply have better registrations (details below).
- I don't think lazr.restful should protect from this abuse, because things can be abused in too many ways, and trying to protect this one in particular makes no sense to me in that context.
- Despite my disapproval, I'm happy to go along with Leonard's review, if James convinces him to make a change like this one.
These are the "better registrations" I suggest. In lib/canonical/ launchpad/ zcml/webservice .zcml ...
- we make our own adapter for
"zope. schema. interfaces. IChoice
zope. publisher. interfaces. http.IHTTPReque st
canonical. launchpad. webapp. vocabulary. SQLObjectVocabu laryBase"
"lazr. restful. interfaces. IReferenceChoic e
zope. publisher. interfaces. http.IHTTPReque st
canonical. launchpad. webapp. vocabulary. SQLObjectVocabu laryBase"
that either returns None (causing Zope to say that there is no adaptation available) or that raises an error (that says something like "Use IReferenceChoice, not IChoice, silly person!"); and
- we change the current registration to
That should accomplish the same thing but within the Launchpad codebase, where it belongs, I argue.
James made two related good points that seem valid to me:
- "the root cause is that there are two different things, using two different criteria, deciding what the field name should be in the API. When they disagree you get problems."
- "A secondary concern is that we want exported objects to be serialised to links, and when that is done for the field name to have _link appended."
Here's the IRC log, for the die-hard reader.
[11:27am] james_w: gary_poster: here's what I was talking about yesterday: https:/ /code.edge. launchpad. net/~james- w/lazr. restful/ object- unmarshal/ +merge/ 22182
[11:28am] • gary_poster looks
[11:29am] gary_poster: james_w: do you want a review?
[11:29am] gary_poster: rephrase:
[11:29am] gary_poster: do you want me to review
[11:29am] james_w: yes please
[11:30am] gary_poster: ok
[11:30am] james_w: I'd like leonard to look as well
[11:30am] james_w: I'm not entirely convinced by the approach as it isn't a great example of elegance, and prevents you doing some odd but legal things.
[11:30am] james_w: but I can't find a better way
[11:32am] gary_poster: james_w: leonard will not be able to before this release (not around today). I agree that he should review. Because he is not around today, this won't make it into the cycle unless we push it as release-critical. My gut feeling so far is that this is more important for developing (that is, future work) that for production (that is, this release). Do you agree?
[11:33am] gary_poster: (IOW, the fact that this will not make the release does not seem like a release-critical problem; but we should get it into the devel branch asap)
[11:33am] james_w: gary_poster: yes, sinzui landed the branch that fixes the problems yesterday, this is to stop any more from creeping in.
[11:34am] gary_poster: james_w: cool. I'll look now to see if I have anything to add, and ma...