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

All INSERT mutations fail, Hasura adds DEFAULT values into generated columns #3681

Closed
nolandg opened this issue Jan 10, 2020 · 2 comments
Closed
Labels
c/server Related to server duplicate This issue or pull request already exists

Comments

@nolandg
Copy link

nolandg commented Jan 10, 2020

When I have a Postgres generated column and attempt to make a Graphql insert mutation, it works perfectly when running as admin role with a Hasura admin secret set in the header.

It fails though for any other role, ie. whenever the admin secret is not set. When I make the insert mutation query without being admin, Hasura adds all fields into the INSERT statement and puts their values as DEFAULT. Postgres then complains that you can't insert into generated columns.

When my table name is work_entry and one of the generated columns is startTime (which casts the start timestamp to time of day) this is the query Hasura makes and Postgres fails on:

INSERT INTO "hdb_views"."manager__insert__public__work_entry" 
    ( "jobId", "createdAt", "startTime", "start", "userId", "end", "endTime", "id", "updatedAt", "duration" ) 
    VALUES ($2, DEFAULT, DEFAULT, DEFAULT, $3, DEFAULT, DEFAULT, $1, DEFAULT, DEFAULT)  RETURNING * )
acdcwelding_postgres | 2020-01-10 22:33:59.835 UTC [129] ERROR:  cannot insert into column "startTime"
acdcwelding_postgres | 2020-01-10 22:33:59.835 UTC [129] DETAIL:  Column "startTime" is a generated column.

There is no default set for all these columns. Why does Hasura stick them into the INSERT query? And why does this work perfectly when querying with a Hasura admin secret header but not without?

I do not have any role presets and the permissions work perfectly for all other fields.

On discord it was pointed out that there is a separate code path for admin inserts vs. non-admin inserts:
https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/RQL/DML/Insert.hs#L254

@nolandg nolandg changed the title Generated columns broken by Hasura adding DEFAULT values into INSERT mutations All INSERT mutations fail, Hasura adds DEFAULT values into generated columns Jan 12, 2020
@marionschleifer marionschleifer added the c/server Related to server label Jan 13, 2020
@GavinRay97
Copy link
Member

GavinRay97 commented Jan 13, 2020

Upon further investigation, this is a duplicate of:

#3572

And it seems will be fixed as a by-product of:

#3598

See comment on issue thread:

#3572 (comment)

Thanks @tirumaraiselvan

@paf31 paf31 added the duplicate This issue or pull request already exists label Jan 14, 2020
@paf31
Copy link
Contributor

paf31 commented Jan 14, 2020

Correct, thanks. I'll close this as a duplicate now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/server Related to server duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants