According to the documentation for EntityFieldQuery::range if you pass NULL as argument, the range directive gets removed.
This is not working as expected. It is not removing the range directive, it is just setting the $start and $length values as NULL.
To reproduce, construct a query as normal, including a range(0,10) condition. Then, set range(NULL, NULL) - or just range() - and execute again.
In entity.inc line 1314, it checks if ($this->range) - which in this case would result in:
range = array(
'start' => NULL,
'length' => NULL,
)
being evaluated as true.
Should the range() function not check if ($start === NULL) before assigning the arguments to the object property? Alternatively, finishQuery() needs to check the individual elements instead of the array.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | drupal-database_range_query_null_issue-1943754-2.patch | 1 KB | andyg5000 |
Comments
Comment #1
andyg5000The ->range() method in entity.inc and includes/database/select.inc both state "The first entity from the result set to return. If NULL, removes any range directives that are set." which is not true as stated by @MaggotMouth above.
This function should only set range values on the query object if the $start argument is something other than NULL. Not doing so generates the following in MYSQL.
LIMIT 0 OFFSET 0
We need to either update these methods to match the documentation of them, or update the documentation. I propose the former so that you can call ->range() ->range(NULL) or ->range(NULL, NULL) and get the correct results.
Patch attached.
Comment #3
andyg5000Whops should be !== since $start will frequently be 0.
Comment #4
andyg5000