Doctrine 1
  1. Doctrine 1
  2. DC-46

Unexpected behavior with whereIn() and empty array

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.12
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None

      Description

      See trac #2064 ( http://trac.doctrine-project.org/ticket/2064 )

      Jwage wrote "This is expected behavior. We cannot and will not add a fake invalid condition to the where string. I think we need to make it throw an exception if you try and pass an empty array."

      I agree that an exception should be thrown.

      But AFAIK this hasn't been implemented yet.

      The issue is quite urgent in my opinion. Example:

      I had a query where I absolutely had to restrict the result set to allowed objects (IDs) only. I used a whereIn() condition for this restriction.

      Problem is: when the user wasn't assigned to any groups, the id-array was empty, and Doctrine removed the WHERE ... IN completely! That resulted in a result set containing all records!

      I would expect

      • either to return no records (correct behavior could be to add "0=1" as a replacement for "... IN ()" expression)
      • or let the database decide (= submitting the query with an empty list which would result - at least for MySQL - in a database exception)
      • or Doctrine could throw an exception

      Would IMO be way better (as its IMO a more expected behavior) than simply not adding the "... IN ()" to the query.

        Activity

        Hide
        Guilherme Blanco added a comment -

        In r6404 this issue was fixed

        Show
        Guilherme Blanco added a comment - In r6404 this issue was fixed
        Hide
        Tim Richter added a comment -

        Throwing an exception is an improvement, but I think it is not the right solution:

        As before the fix, you have to write an extra test for emptyness of the whereIn array, only to save execution of one query and proceed as if the query would give an empty result.

        There is nothing "fake" in a false statement and "x is in the empty array" is false no matter what x is.

        Tim Richter

        Show
        Tim Richter added a comment - Throwing an exception is an improvement, but I think it is not the right solution: As before the fix, you have to write an extra test for emptyness of the whereIn array, only to save execution of one query and proceed as if the query would give an empty result. There is nothing "fake" in a false statement and "x is in the empty array" is false no matter what x is. Tim Richter
        Hide
        gregoire_m added a comment -

        Actually, the exception is never thrown, since there's a test in the andWhereIn() method, before the _processWhereIn() method is called...

        Show
        gregoire_m added a comment - Actually, the exception is never thrown, since there's a test in the andWhereIn() method, before the _processWhereIn() method is called...
        Hide
        David Jeanmonod added a comment -

        Gregoire_m: This ticket have been reopen here: http://www.doctrine-project.org/jira/browse/DC-727

        Show
        David Jeanmonod added a comment - Gregoire_m: This ticket have been reopen here: http://www.doctrine-project.org/jira/browse/DC-727

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Sebastian Busch
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: