这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rakeshkky
Copy link
Member

Description

Using a column in multiple operators in an update mutation generates invalid SQL statement and causing Postgres query error. This PR makes a validation check and throws an appropriate error.

Query:-

mutation {
  update_article(
    _set: {id: 1}
    _inc: {id: 2}
    where: {author_id: {_eq: 1}}
  ){
    affected_rows
  }
}

Error:-

{
  "errors": [
    {
      "extensions": {
        "internal": {
          "statement": "WITH \"public_article__mutation_result_alias\" AS (UPDATE \"public\".\"article\" SET \"id\" = $1,\"id\" = (\"id\"+('2')::integer)  WHERE (('true') AND (((((\"public\".\"article\".\"author_id\") = ($2)) AND ('true')) AND ('true')) AND ('true'))) RETURNING * ) SELECT  json_build_object('affected_rows', (SELECT  COUNT(*)  FROM \"public_article__mutation_result_alias\"      ) )        ",
          "prepared": true,
          "error": {
            "exec_status": "FatalError",
            "hint": null,
            "message": "multiple assignments to same column \"id\"",
            "status_code": "42601",
            "description": null
          },
          "arguments": [
            "(Oid 23,Just (\"\\NUL\\NUL\\NUL\\SOH\",Binary))",
            "(Oid 23,Just (\"\\NUL\\NUL\\NUL\\SOH\",Binary))"
          ]
        },
        "path": "$",
        "code": "unexpected"
      },
      "message": "postgres query error"
    }
  ]
}

Affected components

  • Server
  • Tests

Related Issues

Fix #3432

Solution and Design

Check for same columns present in different operators and if any such column found, raise a validation exception by plumbing in operator names in error message.

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No

Metadata

Does this PR add a new Metadata feature?

  • No

GraphQL

  • No new GraphQL schema is generated

Breaking changes

  • No Breaking changes

Steps to test and verify

Reproduce the issue #3432, instead of unexpected, the server should throw validation error.

Limitations, known bugs & workarounds

@rakeshkky rakeshkky self-assigned this Dec 2, 2019
@rakeshkky rakeshkky added the c/server Related to server label Dec 2, 2019
@netlify
Copy link

netlify bot commented Dec 2, 2019

Deploy preview for hasura-docs ready!

Built with commit 3385027

https://deploy-preview-3458--hasura-docs.netlify.com

@rakeshkky rakeshkky force-pushed the issue-3432-update-multi-ops-bug branch from 86cab62 to 53061cd Compare December 2, 2019 13:22
@hasura-bot
Copy link
Contributor

Review app for commit 53061cd deployed to Heroku: https://hge-ci-pull-3458.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3458-53061cd0

@rakeshkky rakeshkky marked this pull request as ready for review December 2, 2019 14:26
@rakeshkky rakeshkky requested a review from lexi-lambda December 3, 2019 06:33
@hasura-bot
Copy link
Contributor

Review app for commit 0c407d7 deployed to Heroku: https://hge-ci-pull-3458.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3458-0c407d70

@hasura-bot
Copy link
Contributor

Review app for commit 3385027 deployed to Heroku: https://hge-ci-pull-3458.herokuapp.com
Docker image for server: hasura/graphql-engine:pull3458-3385027a

@lexi-lambda lexi-lambda merged commit cb682e2 into hasura:master Dec 3, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-3458.herokuapp.com is deleted

polRk pushed a commit to polRk/graphql-engine that referenced this pull request Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/server Related to server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updating same column with different operators causing postgres query error

3 participants