graphql-engine
graphql-engine copied to clipboard
Unique index constraint appears in studio but fails when used in query, both by admin and user
Example query:
mutation {
insert_table(
objects: [{
key: "test",
product_id: 1,
value: "test",
}],
on_conflict: {
constraint: unique_index_name_as_appear_in_mutation_root,
update_columns: value
}
) {
affected_rows
}
}
Error:
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_table.args.objects",
"code": "constraint-error"
},
"message": "constraint \"unique_index_name_as_appear_in_mutation_root\" for table \"insert_table\" does not exist"
}
]
}
@georgiosd Could you give us a sample repro so we can try it on our end?
@tirumaraiselvan I'm sorry but currently very limited on time...
You need to create a unique index in postgres for { product_id, key, value } and then try the above query
I think this might be related to https://github.com/hasura/graphql-engine/issues/3666#issuecomment-572419941
This was caused by creating a unique index in Postgres instead of a constraint.
We added the unique index using rails which makes a "unique index" that does not have a contraint even though that is not considered proper per https://www.postgresql.org/message-id/CAO8h7BJMX5V1TqzScTx2Nr1jH5iUFG8A071y-g1b_kdzpu9PDw%40mail.gmail.com -- and also sorta a design flaw in postgres that it even allows this, it seems like.
Thanks!
I faced this issue this morning. Seems like a potential bug in Hasura that the constraint is offered as part of the schema if it doesn't work.
I experienced this issue today, any updates?
Have the same issue, using unique index with where filter is not recognized by hasura as constraint
Same here :(
SOLUTION: Do as @rikinsk mentions in #3066 . Add an explicit constraint, not just a unique index.
ALTER TABLE <table_name> ADD CONSTRAINT <constraint_name> UNIQUE (<column1>, <column2> );
Sometimes you can't just alter the table...
@erikhSSI even if this behaviour is a known limitation, there is definitely a schema bug.
I added the constraint manually and reloaded metadata but now Hasura doesn't recognize it. This is really frustrating.
I removed the index and was able to add the constraint manually, no issues with the metadata but this was frustrating to debug.