xpdo icon indicating copy to clipboard operation
xpdo copied to clipboard

Better log for: "Encountered empty IN condition with key id"

Open sebastian-marinescu opened this issue 6 years ago • 4 comments

Feature request

Summary

Sometimes I get this error in the logs:

(ERROR @ /somepath/www/core/xpdo/om/xpdoquery.class.php : 764) Encountered empty IN condition with key id

Looking at this line: https://github.com/modxcms/xpdo/blob/3.x/src/xPDO/Om/xPDOQuery.php#L783 or https://github.com/modxcms/revolution/blob/2.x/core/xpdo/om/xpdoquery.class.php#L764 it doesn't even seem to be something grave - but I'd still like to find the origin of it.

That's why I would like more information on this log.

Why is it needed?

Better debugging and fixing of possible errors.

Suggested solution(s)

I would like to see the complete $query or also where it occurred. I thought I'd get more information by logging $conditions:

$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Encountered empty {$operator} condition with key {$key}: " . print_r($conditions , true));

But logging $conditions didn't help much:

Encountered empty IN condition with key id: Array
(
    [id:IN] => Array
        (
        )
)

If someone can give me a hint, or a recommendation, I'd be happy to test and prepare a PR.

sebastian-marinescu avatar Jan 31 '19 10:01 sebastian-marinescu

This has been present for years. I typically wrap my INs to ensure there is at least one item. The code at line 164 (edited)

 if (in_array(strtoupper($operator), array('IN', 'NOT IN')) && is_array($val)) {
                                $vals = array();
                                foreach ($val as $v) {
                                                               }
}

What is needed:

 if (in_array(strtoupper($operator), array('IN', 'NOT IN')) && is_array($val) && count($val) > 0) 

or

 if (in_array(strtoupper($operator), array('IN', 'NOT IN')) && is_array($val) && !empty($val)) 

wshawn avatar Jan 31 '19 17:01 wshawn

So just step over the case of empty condition-arrays and not do anything about it? Also that would make that before mentioned (and maybe other) error-logs obsolete, would it?

sebastian-marinescu avatar Jan 31 '19 18:01 sebastian-marinescu

My guess is that it would fix the problem if the core was changed to do a quick sanity check. I do the tests in my applications. If the count is 0, skip the whole query. If the count is 1, then I perform an equals instead of an IN. If the count is >1 then perform the IN.

wshawn avatar Feb 01 '19 14:02 wshawn

I was just coming here to report the same issue. [2020-01-18 23:17:06] (ERROR @ /var/www/core/xpdo/om/xpdoquery.class.php : 764) Encountered empty NOT IN condition with key id

It would be fantastic if the error was able to report the class causing the issue (instead of just xpdoquery.class.php). Would that even be possible?

muzzwood avatar Jan 19 '20 02:01 muzzwood