Skip to content

Error in join query not erroring Select call #1932

@SamipJ

Description

@SamipJ

Issue tracker is used for reporting bugs and discussing new features. Please use
Discord or stackoverflow for supporting
issues.

WhereGroup takes a functor as an argument. On certain occasions, functor argument to WhereGroup returns error. This works out fine if I call Select on that query which returns the functor's error as stickyErr in orm.Query

But in the case of a multi-level query where a query is used as a part of join for a bigger query then the sticky error is not honoured and instead is used up in the actual request that goes through.

queryFilter := func(q *orm.Query) (*orm.Query, error) {
    errMsg := fmt.Sprintf("SomeError")
    zap.S().Errorf(errMsg)
    return nil, errors.New(errMsg)
  }

 q1 := serv.client.Model().
    Table("db.table2").
    WhereGroup(queryFilter)

res := make([]*model, 0)
  if err := serv.client.Model().
    Table("db.table1 t1").
    Join("INNER JOIN (?) t2", q1).
    JoinOn("t1.colA = t2.colA").
    Context(ctx).
    Select(&res); err != nil {
    zap.S().Errorf("Error occured: %s",
      err.Error())
    return nil, err
  }

Running the following returns following SQL query due to DebugHook. i.e. query going to db
SELECT * FROM "db"."table1 tc" INNER JOIN (?!(No cluster found)) le ON (tc.tenant_id = le.tenant_id)

Expected Behavior

Should return an error in case any of the queries has a sticky error

Current Behavior

Forms incorrect query

Steps to Reproduce

Mentioned in the initial summary.

Context (Environment)

using following version of library
github.com/go-pg/pg/extra/pgdebug v0.2.0
github.com/go-pg/pg/v10 v10.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions