Closed (fixed)
Project:
Services
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
17 Jun 2011 at 13:51 UTC
Updated:
27 Nov 2012 at 19:44 UTC
Jump to comment: Most recent file
The code in node_resource.inc
drupal_form_submit($node->type . '_node_form', $form_state, $old_node);
makes the assumption that $node->type is allways set.
If not, the absence of type results in the following notices/warnings:
Notice: Undefined index: type in _node_resource_update() (line 282 of /services/sites/all/modules/contrib/services/resources/node_resource.inc).
Notice: Undefined index: _node_form in drupal_retrieve_form() (line 735 of /services/includes/form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_node_form' not found or invalid function name in drupal_retrieve_form() (line 770 of /services/includes/form.inc).
From my point of view it's not desireable to force the client to PUT the node type for an update.
We could just take it from the $old_node object, if not set in the PUT request.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | services-1191786-node-update-type-optional-D6.patch | 5.83 KB | marcingy |
| #21 | services-1191786-node-update-type-optional-D7.patch | 5.46 KB | ygerasimov |
| #20 | allow-no-node-type-2.patch | 4.04 KB | marcingy |
| #18 | allow-no-node-type.patch | 3.89 KB | marcingy |
| #10 | make_type_attribute_optional-1191786-10.patch | 4.7 KB | sanduhrs |
Comments
Comment #1
sanduhrsPatch attached, please review.
Comment #2
kylebrowning commentedComment #3
marcingy commentedThis seems like a good feature however as it stands I can set $node['type'] to be an empty string and it will try to use that value an !empty check would be more appropriate than isset. Also as this is a new feature can you add a test for this?
Comment #4
sanduhrsStill, I think a method that throws notices and warnings instead of returning a meaningful response should be considered a bug.
By the way, the generated response for a request like
is
Which implies to me, that all went well while it didn't.
Bug?
Comment #5
sanduhrsThe new patch checks whether the type attribute ist set and if it's a valid node type.
If not set or invalid it will keep the old value.
The patch inludes three test cases to check for missing, empty and invalid type attribute.
Comment #6
marcingy commentedThis still does not take into account that node type can be empty with the isset check. Plus there is no need to do an !array_key_exists($node['type'], $node_types)) check instead you can do an isset for this. This should be used as it is more performant.
Comment #7
sanduhrsWell, if the node type doesn't exist, the same error occurs, as if none or empty is given.
So to be sure, we need to check if the node type is valid
array_key_exists($node['type'], $node_types))This also takes into account when type is empty.
Can we assume that the $old_node->type is valid per se as I do in that patch?
Probably not, because some administrator could have deleted it.
I'm not sure what to do in that case.
Comment #8
sanduhrsTo prevent the error from occuring, we need to check for a valid node type parameter in any case.
Whether it has been submitted or not doesn't make a difference.
I tried to check for validity with a simple
function_exists($node['type'] . '_node_form'), but that didn't work out.Any other ideas for a better performing solution?
Attached is a patch that checks for isset, empty and validity.
It returns 406 in case of invalidity.
Comment #9
marcingy commentedThis can simplified
as empty will return false if the item does not exist or is ''.
Also you need to add periods after your comments.
The approach of making sure the node type is valid is a really good idea, once the above is done this should be good to go. I haven't run the tests yet but they look sane from an eyeball.
Comment #10
sanduhrsChanged, as you suggested.
Comment #11
sanduhrsPlease review.
Comment #12
marcingy commentedThanks looks good.
Comment #13
kylebrowning commentedif we can get a 6.x version that would be great.
Comment #14
kylebrowning commentedComment #15
killua99 commentedI don't know where to put this notice:
Notice: Undefined variable: final_resource en services_edit_form_endpoint_resources_submit() (línea 396 de ~/sites/all/modules/services/plugins/export_ui/services_ctools_export_ui.class.php).
Comment #16
marcingy commentedGrabbing to reroll this weekend
@Killua99 please raise a new issue as your post is not related to this issue at all thanks.
Comment #17
killua99 commentedOk then.
Comment #18
marcingy commentedNew version of the patch to allow updates to ignore type. As per normally I'll backport after d7 version is rtbc.
Comment #19
ygerasimov commentedI think there is no need to check whether $old_node->type is available as we did node_load before.
Also we can avoid checking whether content type is valid if we loaded it from old node:
Everything else I am happy with. Thanks for great work @sanduhrs and @marcingy!
Comment #20
marcingy commentedReroll with changes above
Comment #21
ygerasimov commented@marcingy, what do you think about attached patch. Code is just moved around but in my opinion looks bit clearer.
Comment #22
marcingy commentedLooks good would like Kyle to commit this and give a once over - I'll happily roll a d6 version of the patch once this is committed.
Comment #23
kylebrowning commentedPort it!
Comment #24
marcingy commentedReroll for d6
Comment #25
marcingy commentedWould be nice to get this into 3.2 ;)
Comment #26
kylebrowning commentedlooks great.
Comment #27
kylebrowning commentedactually this break in 6.x
Comment #28
kylebrowning commentedComment #29
kylebrowning commented