question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

soft column presets during insert/update

See original GitHub issue

I’m doing an insert mutation that fails when run with a particular limited role:

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_xs_y_one.args.object.x.data.user_id",
        "code": "validation-failed"
      },
      "message": "field \"user_id\" not found in type: 'xs_insert_input'"
    }
  ]
}

with a particular role.

I’ve verified the permissions – the role is allowed to set the user_id value and the token contains the correct and expected claims.

The mutation should insert into two tables: the mutation object writes to the child table, and this table has an object relationship to a parent table, where the foreign key does include the user_id column. I have tried setting the user_id value on each of the child and parent objects, as well as both, and all of these cases error.

The problem appears to be a “Column Preset” – the column preset in this case is set to X-Hasura-User-Id which is the same value for user_id that is being passed in the mutation. If the column preset is removed, then the mutation works (but of course no longer works if the user_id is not specified in the mutation). If the column preset is left, then the mutation only works if no user_id is specified in the mutation.

I don’t believe this should be the case – the column preset should default a missing value, not prevent a mutation that contains the value from working (and furthermore, the value passes all the permission checks and matches the preset).

Failing configuration:

image

Working configuration, same as above, without user_id column preset.

Hasura v2.13.2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
carlpatencommented, Jan 26, 2022

FYI, without soft presets, there is no backwards-compatible migration path away from presets. In our org we’ve concluded that we should avoid presets and rely entirely on permissions instead, but we have no easy way of getting rid of our existing presets without breaking the app for existing users.

1reaction
rocketramancommented, Oct 13, 2020

Column presets are hard presets and this is by design. Hence, they are removed from the schema as well.

@tirumaraiselvan If that is true, the documentation is really not clear about this. Here is what the section about column presets (https://hasura.io/docs/1.0/graphql/core/schema/default-values/column-presets.html#column-presets) says – I’ve bolded elements of this that imply these are soft presets, not hard presets.

Let’s say you want certain fields to have their values set automatically when not explicitly passed using session variables or fixed values when a new row is created with a particular user role.

Hasura GraphQL engine’s column presets let you define role-based default values for any field/column. These values can either be a session variable value or a static value.

In fact, the whole section is named “Setting default values for fields using role-based column presets”. The term “default” implies a soft preset, not a hard preset.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you skip default value columns on insert/update in ...
I've tried setting that column to readonly and autogenerated, so it stopped trying to put in DateTime.MinValue, but it doesn't seem to be ......
Read more >
Column Presets - Welcome to Solve - ControlUp Support
Solve has default presets which are configured to show relevant columns for common scenarios. The current preset is indicated at the top right...
Read more >
upsert, soft delete the sink Delta parquet - Microsoft Q&A
Hello, How is it possible to have the sink Delta parquet file to upsert (update/insert) as well as a soft delete. For example,...
Read more >
ColumnProperties - HVR 6 Documentation - Fivetran
This parameter defines the actual name of the column in the database location, as opposed to the column name that HVR has in...
Read more >
Insert, Update, and Delete Data from a Database Examples
In your Studio flow, select the Insert operation. In the Advanced tab, set the Auto generate column names field to Expression or Bean...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found