propagate context to From selector in (*query).selector (#4501)

This commit is contained in:
Michael Caulley
2026-05-15 17:48:22 -04:00
committed by GitHub
parent 1391816b77
commit 0a61da2fa2
2 changed files with 8 additions and 0 deletions

View File

@@ -1070,6 +1070,7 @@ func (q *query) selector(ctx context.Context) (*sql.Selector, error) {
WithContext(ctx)
if q.From != nil {
selector = q.From
selector.WithContext(ctx)
}
selector.Select(selector.Columns(q.Node.Columns...)...)
if order := q.Order; order != nil {

View File

@@ -164,6 +164,13 @@ func TestMySQL(t *testing.T) {
require.Len(t, sib, 2)
require.True(t, slices.ContainsFunc(sib, func(u *ent.User) bool { return u.Name == el.Name }))
require.True(t, slices.ContainsFunc(sib, func(u *ent.User) bool { return u.Name == jo.Name }))
// Cross-schema edge predicate: QueryGroups().Where(HasUsersWith(...))
// must qualify group_users with db2, since the connection defaults to db1.
got := a8m.QueryGroups().
Where(group.HasUsersWith(user.ID(a8m.ID))).
CountX(ctx)
require.Equal(t, 1, got) // a8m was removed from GitHub above; only GitLab remains
}
func TestVersionedMigration(t *testing.T) {