Skip to content

Conversation

@Vovan-VE
Copy link

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Unexpected for loop consumes all the rows from the result set. Looks like it's a copy-paste mistake from similar slice case. Here must be if instead.

User Case Description

for rows.Next() {
	var id int64
	if err := tx.ScanRows(rows, &id); err != nil {
		return err
	}
	// ... id ...
}

Unexpected `for` loop consumes all the rows from the result set. Looks
like it's a copy-paste mistake from similar slice `case`. Here must be
`if` instead.
@propel-code-bot
Copy link
Contributor

Correct copy-paste typo: use if instead of for in single value scan

This pull request fixes a copy-paste error in the Scan function of scan.go, replacing an unintended for loop with an if statement for cases where the scan destination is a single value (such as *int, *string, *time.Time, etc.). The original logic incorrectly iterated through all rows, potentially consuming the entire result set rather than handling a single row, which could cause unexpected behavior when scanning into scalar types. This change ensures that only a single row is consumed when these types are used.

Key Changes

• Replaced for initialized || rows.Next() with if initialized || rows.Next() in the Scan function case for single value destinations in scan.go.

Affected Areas

scan.go (specifically the Scan function logic for scalar destination types)

This summary was automatically generated by @propel-code-bot

@jinzhu
Copy link
Member

jinzhu commented Oct 26, 2025

thank you for your pr, that’s intentional, it ensures all returned rows are read so the last one can be selected.

@jinzhu jinzhu closed this Oct 26, 2025
@Vovan-VE
Copy link
Author

@jinzhu , are you sure? Destination is a single scalar value like int, not []int to take them all. Since query.Take(&model) and query.Take(&id) works as it looks, why for rows.Next() works only for &model, but not for &id? It's confusing and counterintuitive.

for rows.Next() {
	var id int64
	if err := tx.ScanRows(rows, &id); err != nil {
		return err
	}
	// ... id ...
}

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.

2 participants