Skip to content

Fix buildLimit() silently dropping OFFSET 0#1173

Open
darkspock wants to merge 1 commit intoyiisoft:masterfrom
darkspock:fix/build-limit-offset-zero
Open

Fix buildLimit() silently dropping OFFSET 0#1173
darkspock wants to merge 1 commit intoyiisoft:masterfrom
darkspock:fix/build-limit-offset-zero

Conversation

@darkspock
Copy link
Copy Markdown

Summary

AbstractDQLQueryBuilder::buildLimit() uses !empty($offset) to decide whether to append the OFFSET clause. Since empty(0) returns true in PHP, an explicitly set OFFSET 0 is silently dropped from the generated SQL.

While OFFSET 0 has no semantic effect on query results, this is inconsistent: a value explicitly set by the caller should be reflected in the output. It can also cause confusion when debugging generated SQL.

Fix

Replace !empty($offset) with $offset !== null, which correctly distinguishes "no offset set" (null) from "offset is zero" (0).

Before

if (!empty($offset)) {

After

if ($offset !== null) {

Risk

Very low — the only change is that OFFSET 0 now appears in the SQL when explicitly set. This has no effect on query results.

!empty($offset) evaluates to false when $offset is integer 0, causing
OFFSET 0 to be silently omitted from the generated SQL. While OFFSET 0
has no semantic effect, this is inconsistent: an explicitly set offset
should appear in the output.

Replace with $offset !== null which correctly distinguishes "no offset"
(null) from "offset zero" (0).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (dffa745) to head (50a73f0).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1173      +/-   ##
============================================
- Coverage     98.62%   97.83%   -0.80%     
  Complexity     1645     1645              
============================================
  Files           120      120              
  Lines          4292     4292              
============================================
- Hits           4233     4199      -34     
- Misses           59       93      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}

if (!empty($offset)) {
if ($offset !== null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is necessary. At least if there is no real case where it is needed.

Copy link
Copy Markdown
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"no offset set" (null) and "offset is zero" (0) gives equal result in SQL. I agree with @Tigrov and suggest don't change it.

But it will be useful to add an explanation to the description of methods that set offset.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants