Skip to content

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

Open

Description

@sebastian-marinescu

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.

Activity

  1. wshawn commented on Jan 31, 2019

    @wshawn

    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)) 
    
  2. sebastian-marinescu commented on Jan 31, 2019

    @sebastian-marinescu
    Author

    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?

  3. wshawn commented on Feb 1, 2019

    @wshawn

    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.

  4. muzzwood commented on Jan 19, 2020

    @muzzwood

    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?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions