Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialect/sql/builder: make sql.In() with empty args fallback to False() #2735

Merged
merged 5 commits into from Jul 11, 2022

Conversation

Liooo
Copy link
Contributor

@Liooo Liooo commented Jul 10, 2022

Encountered a SQL syntax error when executing sql.In("col", []interface{}). The new test case compiles into "SELECT * FROM "users" WHERE "a" = $1 OR" without this PR change.

entc generated code at ent/<modelname>/where.go has the same FALSE fallback logic but sql.In didn't, and I'm assuming this is not the expected behavior.

Copy link
Member

@a8m a8m left a comment

Choose a reason for hiding this comment

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

Looks good @Liooo! Thanks for working on it.

return p
return p.False()
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

We can also remove this if-statement from the codegen.

Copy link
Contributor Author

@Liooo Liooo Jul 11, 2022

Choose a reason for hiding this comment

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

We can also remove this if-statement from the codegen.

Really agreed, fixed in 52c502b 🙏

return p
return p.False()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return p
return p.False()
// If no arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
return p.False()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks added in f1fcc1c 👍

@@ -1535,8 +1535,10 @@ func In(col string, args ...interface{}) *Predicate {

// In appends the `IN` predicate.
func (p *Predicate) In(col string, args ...interface{}) *Predicate {
// if not arguments were provided, append the FALSE constants,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// if not arguments were provided, append the FALSE constants,
// If no arguments were provided, append the FALSE constants,

if len({{ $arg }}) == 0 {
s.Where(sql.False())
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Run go generate ./... from the root of the project.

Copy link
Member

@a8m a8m left a comment

Choose a reason for hiding this comment

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

🚀

Thanks for the contribution @Liooo

@a8m a8m merged commit b00e549 into ent:master Jul 11, 2022
@Liooo
Copy link
Contributor Author

Liooo commented Jul 11, 2022

@a8m

thanks for the review 🙌

@Liooo Liooo deleted the fix-empty-sql-in branch July 12, 2022 07:31
adayNU added a commit to adayNU/ent that referenced this pull request Jul 14, 2022
…se()

This is basically the identical change to ent#2735, but for NotIn().

This bug currently prevents anyone using NotIn() from upgrading from v0.10.x to v0.11.x
a8m pushed a commit that referenced this pull request Jul 19, 2022
… FALSE (#2757)

* dialect/sql/builder: make sql.NotIn() with empty args fallback to False()

This is basically the identical change to #2735, but for NotIn().

This bug currently prevents anyone using NotIn() from upgrading from v0.10.x to v0.11.x

* Update go.sum

untidy

* feedback
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.

None yet

2 participants