ent: Query pagination error: wrong number of arguments to function COUNT()

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior ๐Ÿ˜ฏ

query := client.MyModel.Query()
r, err := query.Select(fields...).Paginate(...)

err is โ€œwrong number of arguments to function COUNT()โ€

Expected Behavior ๐Ÿค”

Should return results normally as in version 0.10.0

Your Environment ๐ŸŒŽ

Tech Version
Go 1.19.1
Ent 0.11.3
Database SQLite3
Driver github.com/mattn/go-sqlite3 v1.14.15

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (2 by maintainers)

Most upvoted comments

Hello @vincentluan, Iโ€™m so happy because the issue was gone.

The master branch is stable enough for use in the production environment (with the go.mod file as version locking). However, I will ask @a8m to create a new tag for the new users without having the same issue.

We welcome you to our community on Discord for faster support and response: https://discord.gg/qZmPgTE6RX

Again, thank you so much for reporting the issue and the effort for it.

@giautm itโ€™s working now, thanks a lot for your help ๐Ÿ˜„

Hey guys, it seems that the declaration of fieldSeen will be missing when using Annotations(entgql.Skip()) in schema:

func (MyModel) Fields() []ent.Field {
	return []ent.Field{
		field.Uint64("table_1_id").
			Annotations(entgql.Skip()),
		field.Uint64("table_2_id").
			Annotations(entgql.Skip()),
	}
}

The error with function COUNT() is still happening with the latest version in master branches, using the same query as in my original example. Here is how I create the test client:

client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")

This will cause the error when fields contains 2 or more field names:

client.MyModel.Query().Select(fields...).Paginate(
    ctx, after, first, before, last, ent.WithMyModelOrder(orderBy), ent.WithMyModelFilter(whereInput.Filter),
)
# go.mod
entgo.io/contrib v0.4.6-0.20230514215512-b00990bedaf0
entgo.io/ent v0.12.4-0.20230523115418-d7b3a6c4f4dc

Hello @a8m, this is still happening and I have upgraded both ent and contrib to the latest commit on master. And another error has presented itself: one of the collectField function in gql_collection.go is missing its declaration for fieldSeen and other variables.

# go.mod
entgo.io/contrib v0.4.6-0.20230514215512-b00990bedaf0
entgo.io/ent v0.12.4-0.20230512075626-36553bbd8a9b