Fix queryScalar() state mutation by using clone#1172
Open
darkspock wants to merge 1 commit intoyiisoft:masterfrom
Open
Fix queryScalar() state mutation by using clone#1172darkspock wants to merge 1 commit intoyiisoft:masterfrom
darkspock wants to merge 1 commit intoyiisoft:masterfrom
Conversation
queryScalar() was manually saving and restoring select, orderBy, limit, and offset properties around createCommand(). This is fragile: if createCommand() throws, the original state is never restored. It is also not safe if properties are referenced elsewhere. Replace with clone $this, which is already the pattern used in the else branch (line 856) and in withTypecasting(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1172 +/- ##
============================================
- Coverage 98.62% 98.62% -0.01%
Complexity 1645 1645
============================================
Files 120 120
Lines 4292 4284 -8
============================================
- Hits 4233 4225 -8
Misses 59 59 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Tigrov
approved these changes
Apr 2, 2026
Member
Tigrov
left a comment
There was a problem hiding this comment.
Needs to add a line to changelog.
vjik
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Query::queryScalar()manually saves and restoresselect,orderBy,limit, andoffsetproperties aroundcreateCommand(). This is fragile:createCommand()throws an exception, the original state is never restoredelsebranch (line 856) which already creates a new Query instanceBefore
After
The clone approach is already the established pattern in this codebase (see
withTypecasting()).Risk
Low — the clone produces identical SQL output. The only behavioral change is that the original Query object is no longer temporarily mutated.