The docs of SelectInterface::range() read:

* @param $start
* The first record from the result set to return. If NULL, removes any
* range directives that are set.

The implementation is:

public function range($start = NULL, $length = NULL) {
  $this->range = func_num_args() ? array('start' => $start, 'length' => $length) : array();
  return $this;
}

It appears that the behavior depends on the number of arguments given, not on the value of $start. EntityFieldQuery has a similar range() method and may supply NULL, NULL to Select::range(). In those cases, the query will never return any results.

My suggestion is to not depend on func_num_args() but actually check the value of $start when it is used.

I will supply patches in a couple of minutes. The bug also exists in Drupal 7, the code is still very similar.

I actually recommend that the handling of $start and $length be split, but that is more of a feature request than a bug.

Comments

Jorrit’s picture

StatusFileSize
new1014 bytes

Test only patch.

Jorrit’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, range-reset-1806606-1-test-only-d8.patch, failed testing.

Jorrit’s picture

Status: Needs work » Needs review
StatusFileSize
new2.04 KB

The patch with the fix.

Status: Needs review » Needs work

The last submitted patch, 4: range-reset-1806606-3-d8.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

daffie’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new858 bytes
new1.48 KB

Look what I found. A bug with a fix. Only 4 years old!
I rerolled the patch. Some minor changes to clean up the test a bit.

Good find Jorrit!

@Jorrit: The patch that you made is almost RTBC for me. If you like my changes you can change the status to RTBC.

daffie’s picture

Issue tags: +Needs backport to D7

In the issue summary:

The bug also exists in Drupal 7

Status: Needs review » Needs work

The last submitted patch, 8: 1806606-8.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new857 bytes
new1.48 KB

Minor mistake

Jorrit’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me!

alexpott’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed and pushed b9fc15d6225366e7580adf8c5fc3240dbf865632 to 8.2.x and cc9f4c1 to 8.1.x. Thanks!

So we need to open a new issue for D7 and then this one can be marked as fixed.

  • alexpott committed b9fc15d on 8.2.x
    Issue #1806606 by daffie, Jorrit: Drupal\Core\Database\Query\Select::...

  • alexpott committed cc9f4c1 on 8.1.x
    Issue #1806606 by daffie, Jorrit: Drupal\Core\Database\Query\Select::...
daffie’s picture

  • alexpott committed b9fc15d on 8.3.x
    Issue #1806606 by daffie, Jorrit: Drupal\Core\Database\Query\Select::...

  • alexpott committed b9fc15d on 8.3.x
    Issue #1806606 by daffie, Jorrit: Drupal\Core\Database\Query\Select::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.