New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sebastian-marinescu opened this Issue Jan 31, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@sebastian-marinescu
Copy link

sebastian-marinescu commented Jan 31, 2019

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.

@wshawn

This comment has been minimized.

Copy link

wshawn commented Jan 31, 2019

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)) 
@sebastian-marinescu

This comment has been minimized.

Copy link
Author

sebastian-marinescu commented Jan 31, 2019

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?

@wshawn

This comment has been minimized.

Copy link

wshawn commented Feb 1, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment