Closed (fixed)
Project:
Services
Version:
7.x-3.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
6 Mar 2011 at 20:33 UTC
Updated:
20 Aug 2013 at 14:20 UTC
Jump to comment: Most recent file
Comments
Comment #1
gddSo I remember committing this in order to fix a bug a while back here
https://github.com/heyrocker/services/commit/08ae9ab8b5ddbc9934e3a43cd5b...
I don't think it was related to the commit you posted (or if it was I couldn't see it.)
Unfortunately I don't remember what problem I was trying to fix there, even though I left a comment on it. It looks to me like it was trying to grab all GET arguments as a parameter in situations when it shouldn't. Does this make sense to you? Sorry I don't have more details, it was several months ago.
Comment #2
Hugo Wetterberg commentedWhat you "fixed" was the intended behaviour :). If you don't want all the GET-arguments you simply have to specify the one you do want.
Comment #3
kylebrowning commentedBoth of these patches result in 39 failed tests. Either the tests break after using this, or this patch is really not needed.
Im not entirely sure I understand the issue?
Comment #4
kylebrowning commentedBoth of these patches result in 39 failed tests. Either the tests break after using this, or this patch is really not needed.
Im not entirely sure I understand the issue?
Comment #5
Hugo Wetterberg commentedThe patch is needed. The issue is that it's not possible to send all get-parameters as an argument to a function. This makes it pretty much impossible to write a decent index handler.
Comment #6
kylebrowning commentedApplying these patches causes node_resource, among others to fail.
FIrstly, function _node_resource_access($op = 'view', $args = array()) returns false because $args is now an array with index 0 thats equal to an array of ['node'].
All of the code is expecting that the $args(which should probably be called $node all things considered) that its the only argument we need.
Second, _node_resource_create fails because its expecting $node to come through, but instead its now array(1) {
["node"]=>
<(3) {
["title"]=>
<(4) "test"
["type"]=>
<(5) "story"
["body"]=>
It doesnt make any sense to to say $node = $args['node'], when we can have the argument build function handle the correct argument
I think the way we have it makes much more sense. Each parameter that the function requests, its gets, as opposed to all of them and in some array.
Maybe all of our resources functions need to be changed to accommodate this, but if thats the case, this patch needs work.
Comment #7
kylebrowning commentedComment #8
Hugo Wetterberg commentedWell, of course that's what you get if you pass in the node as array('node'=>array('title'=>..)). One of the points with REST is that you post the actual resource, you should be posting this instead: array('title'=>..). That it's a node you're posting is already deduced from the URI, the "'node'=>"-wrapper is superfluous. That's why the tests fail, they were based on the faulty change in the REST server.
Here's one effect of the change:
https://github.com/hugowetterberg/services-3.x-sample/issues/1
/Hugo
Comment #9
voxpelli commentedIf I understand this issue correctly then I surely think that it should be corrected.
However - we're rather late in the development cycle - we've gotten a few rc:s out there and this is quite a big API change so I think we would need to ease the changes needed by users as much as possible. We could perhaps add code that emulates the current "wrong" behavior in the resources?
Who would like to make a patch? Hugo? Kyle? Could the one of you who would like to roll a patch assign this issue to himself?
Comment #10
Hugo Wetterberg commentedWell, there is a patch. For the core issue at least, it doesn't fix the tests though.
Comment #11
kylebrowning commentedIll fix the tests
Comment #12
kylebrowning commentedok, how about this as a patch for d7.
Comment #13
voxpelli commentedLooking at the code and the commit refered to in the issue description then I don't see how any of these patches restores the old functionality of:
Neither of these two patches makes any good use of the argument type - why are we defining a type if we don't care about it? If we only go by name or by source type then the argument type is useless? Shouldn't we perhaps take the argument type into consideration?
Couldn't an alternate solution to this be to add some new data sources instead? The new data source could explicitly be unsupportive of data types and always return the full source - like what Hugo wants. I attach a patch for that suggestion.
Edit:
Also - how are these changes affecting the way the resources works in other servers like XML-RPC of AMF?
Comment #14
Hugo Wetterberg commentedWell I agree with you that the types, and the coercion of types, needs some work. But the reason that you don't find anything done about types is that this issue is about the argument source handling, not argument type handling. So, yes, I agree with you, but it's off-topic.
Comment #15
kylebrowning commentedIM not sure will that leaves this patch....
Comment #16
voxpelli commentedAfter thinking about it I'm with hugo on this one - the first patch here is what we should go with. It just need to be extended with changes in tests and resources to accommodate the "new old" behavior as well as to make the resources still accept the old kinds of argument (something that the resources should do in themselves - the rest server doesn't have to do anything about it).
So - we need changes in tests and resources as well before RTBC.
Comment #17
kylebrowning commentedWhats wrong with the patch I provided? It allows the old arguments to still be accepted, and it requires no changing one resource or test.
Comment #18
voxpelli commented@kyle: That it prohibits any parameter to contain an array with a parameter of it's own name which could lead to very weird bugs
Comment #19
marcingy commentedCan some confirm my understanding of this issue is correct?
If a resource has 3 parameters I can pass in array('parm1', 'parm2', 'parm3') vs posting parm1, parm2, parm3 as seperate strings and then the server converts the array into arg understood by services?
Are both options are allowed depending on the server? If so then I'm not massively concerned and would say the old style servers (xml-rpc, amfphp) can happily remain with args being specified at a string level as I can't see many site posting the same request to xml-rpc and json or indeed switching between the protocals.
Comment #20
Hugo Wetterberg commented@marcingy No, thats not it. After the patch the you can post the resource as array('parm1', 'parm2', 'parm3'), as the original behaviour was. Posting parm1, parm2, parm3 as separate strings is not something you do in REST, but rather sounds like something you would do in a RPC-style server. The issue is that somewhere along the line the REST server was changed so that you have to pass array('resource'=>array('parm1', 'parm2', 'parm3')), which is redundant in the extreme, and it was probably done because of a lack of understanding of how the REST server works. This also broke the ability to pass all GET-parameters as a parameter, which is extremely handy when you need more dynamic options.
Comment #21
Hugo Wetterberg commentedThe RPC servers ignore the source attribute and won't be affected. The issue is really about dealing with those clients who have been using the RC:s of the REST server and therefore have used the current way of passing resource information. Some kind of backward comparability must be provided for them.
Comment #22
kylebrowning commentedThats what my patch in #12 fixes. It accepts args the old way, and the way Hugo intended them to be accepted, theres nothing else that needs to be changed.
Comment #23
marcingy commentedHugo thanks for your illustration that makes sense and was kind of what I was getting at but I failed to explain it very well. I agree we need to use an approach that does not affect backwards comptability as there are now sites based on on 3.x services (and personally from the work I have been doing in tests I like the current approach but making the calls lighter and hence more flexible also makes sense).
I think the patch proposed by Kyle is a sensible starting point as it takes the current approach and extends it with Hugo patch propose initially in this issue, it does have some style issues and could be simplified as an elseif statement.
It might be worth getting heyrocker opinion on this issue so as we can get this resolved and make services even better :)
Comment #24
voxpelli commentedAs I said in #18 I think that kyles patch introduces some inconsistencies by prohibiting any full object argument from containing a key with the name of the argument itself. That is not something you would expect the code to do and thus it can lead to nasty errors that are hard to debug.
The full object should take precedence over a named parameter to ensure a consistent behavior. That means that we can't fix the backwards compatibility in the argument resolver but needs to fix it within the resources themselves.
I 'm therefor suggest that we go with Hugo's original patch and patch our own resources to be backwards compatible. I'm attaching a patch that fixes some of our resources.
Comment #25
kylebrowning commentedCan you write a test for this. I still dont understand after our conversation in IRC. Bumping to critical as this is a launch blocker.
Comment #26
sanduhrsRerolled a patch containing the original approach and #24.
* Argument handling as suggested
* All resources backwards compatible
* Adjusted tests accordingly
* All tests passed before and after modification
Comment #27
kylebrowning commentedAll of your tests pass but only for the new way, How can we be sure the old way still works?
Comment #28
kylebrowning commentedComment #29
voxpelli commented@kylebrowning: The old way can't work any more - it's a regression that it's impossible to support any longer (And yes - I need to take some time to show you that in the form of a test - but I haven't had the time to do that yet)
Comment #30
kylebrowning commentedI thought we decided that the old way must continue to work since we are in release candidate.
Comment #31
voxpelli commentedOh yeah - forgot that we was going to achieve that at a resource level - true - that's what should be tested - that the current resources works with old type of requests. So we need to duplicate all the tests of the affected resources :)
Comment #32
kylebrowning commentedinstead of duplicating, it might be possible to have each test call itself but pass in a value like true for old way. So the first pass through tests the new way when those tests are done, call the same tests again but pass in TRUE, and then test the old way.
Or maybe thats too complicated, but doubling our tests just sounds like well have way too many tests :(
Comment #33
sanduhrsDuplicating would be less time consuming. And it'll be easier to remove them in future versions.
Comment #34
kylebrowning commentedok just duplicate them then. we also need this for 6.x as well :(
Comment #35
sanduhrsRerolled the patch with legacy tests included.
Comment #36
sanduhrsJust finished the tests. All pass without errors.
Comment #37
sanduhrsI will try to backport this to D6 when the patch for D7 is ready to go.
Review anyone?
Comment #38
kylebrowning commentedThis look great. All tests pass, and it works well. thank you!
Comment #39
sanduhrsDoes anyone know something about the status of simpletest in D6?
It seems it doesn't install autoload module and generates a bunch of failures when testing services.
Comment #40
kylebrowning commentedhrmm, the tests all pass for me. on php 5.2 and php 5.3
Comment #41
sanduhrsAllright, attached is a tested patch for D7 and an untested one for D6.
I tried testing D6 on a fresh Drupal install in my DEV environment and on two different freshly installed VMs (Ubuntu 10.04, Ubutu 10.10) without success.
Could someone else take over, please?
Comment #42
didlix commentedWorks for me! (d 6.20)
Comment #43
kylebrowning commentedThere was one minor fix for Drupal 6. Ive fixed that and committed the patch in #41, All tests pass.
Now on to d7.
Comment #44
kylebrowning commentedFixed, committed in both d6 and d7.
Comment #45
kylebrowning commentedComment #46
sitiveni commentedHi, sorry for bothering you guys about this closed issue. However, I just upgraded to services 6.x-3.0-rc2 and run a couple of tests to retrieve node resources. So basically a simple http://mydomain.com/rest/node/666. This did not end up successfully and i got no results returned...
I tried to figure out what the problem is and came to function _node_resource_access().
At beginning of the function there's param $args:
Just after the first condition if (isset($args[0]['node'])), variable $args contains:
There's apparently no array key node available. Nevertheless, the isset condition appears to return true and the new $args[0] value is taken from $args[0]['node'] (which is 6? interesting...).
Can't explain why isset() returns true despite that args[0]['node'] does not exist (apparently "is not set"). What did it for me was adding array_key_exists() to the condition (is_array() is required otherwise array_key_exists returns a warning as "The second argument should be either an array or an object"):
I've only checked node resource so far, maybe it's the same for other resources too.
Comment #47
kylebrowning commentedDuplicate of #1236316: Retrieve requests for node, user, comment file resource return empty result
Can you please please provide a patch?
Comment #48
mradcliffeFinding that this commit breaks everything took some time this afternoon.
hook_services_resources() needs updating. I would even go so far as to update the release notes with how critical of an API change it is.
Should I open this back up or open a new issue?
Comment #49
voxpelli commented@mradcliffe: New issue - this one has been solved - any issues it might has caused should be posted as follow up issues. You might link to them from here though if you want to make sure that everyone here knows about them.
Comment #50
bekirdag commentedWhy the data array size is limited to 1 on line 374
count($data) == 1
Why there is this control?