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

Error in join query not erroring Select call #1932

Open
SamipJ opened this issue Nov 30, 2021 · 0 comments
Open

Error in join query not erroring Select call #1932

SamipJ opened this issue Nov 30, 2021 · 0 comments

Comments

@SamipJ
Copy link

SamipJ commented Nov 30, 2021

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

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

No branches or pull requests

1 participant