Obviously I'm doing something wrong while testing data types with wsclient, but Rules should not end up in a fatal error. Code fragment in rules.core.inc:
public function applyDataSelector($selector) {
$parts = explode(':', str_replace('-', '_', $selector), 2);
if (($vars = $this->availableVariables()) && isset($vars[$parts[0]]['type'])) {
$data = NULL;
$wrapper = rules_wrap_data($data, $vars[$parts[0]], TRUE);
if (count($parts) > 1 && $wrapper instanceof EntityMetadataWrapper) {
try {
foreach (explode(':', $parts[1]) as $name) {
$wrapper = $wrapper->get($name);
}
}
// In case of an exception or we were unable to get a wrapper, return FALSE.
catch (EntityMetadataWrapperException $e) {
return FALSE;
}
}
}
return isset($wrapper) ? $wrapper : FALSE;
}
EntityMetadataWrapper does not implement a get() method, so the instanceof check is wrong here. Only EntityStructureWrapper and EntityListWrapper implement a get() method, so should we check for that instead?
Comments
Comment #1
klausiSame error in rules.states.inc when executing the rule from code:
Fatal error: Call to undefined method EntityValueWrapper::get() in rules/includes/rules.state.inc on line 277
Comment #2
fagoIf the problem stems from your code providing wrong info, there is no bug but a feature-request to improve DX when wrong property info is specified/used.
We could wrap the get() call into a suiting check and bail out nicely if necessary.
Comment #3
klausiIn my case i had a struct data type without property information. entity_metadata_wrapper() returns an EntityValueWrapper for that , which seems to be wrong and should be fixed, too. However, Rules should also check for the correct classes, patch attached.
Comment #4
fagolooks good, thanks committed.