hasura / hasura/graphql-engine

Transactions don't rollback when using Namespace

Open
#9,877 2 comments 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Current server version: v2.20.1-ce
Console asset version: 1678719117500

### Environment

PostgreSQL 12.9 (Debian 12.9-1.pgdg110+1) on x86_64-pc-linux-gnu
Running in Docker container

We have two PostgreSQL databases.
- Database_one has no namespace
- Database_two has Root fields namespace in use, `namespace_for_database2` in examples.

### What is the current behaviour?

```
mutation example(args...) {
namespace_for_database_two {
upsert_parent(args..) {
affected_rows
__typename
}
delete_child_elements(args...) {
affected_rows
__typename
}
insert_child_elements(args) {
affected_rows
__typename
}
__typename <-- remove this and it works as expected.
}
}
```
When `insert_child_element` hits constraint in our database and fails, two previous mutations are still committed to the database, this means that all child elements are gone and no new ones are created.

### What is the expected behaviour?

I would expect this to rollback all the mutations because mutations are made to same database and are from one request.

### Any possible solutions/workarounds you're aware of?
If `__typename` is removed from namespace root field this mutation works as expected. eg:
```
mutation example(args...) {
namespace_for_database_two {
upsert_parent(args..) {
affected_rows
__typename
}
delete_child_elements(args...) {
affected_rows
__typename
}
insert_child_elements(args) {
affected_rows
__typename
}
}
}
```
Also if root field namespace is removed from database_two this mutation works as expected, even with that "breaking" `__typename_ eg:
```
mutation example(args...) {
upsert_parent(args..) {
affected_rows
__typename
}
delete_child_elements(args...) {
affected_rows
__typename
}
insert_child_elements(args) {
affected_rows
__typename
}
__typename
}
```

These workarounds are not enough for us for two reasons. We really want to use Namespaces and we use Apollo Client (it adds `__typename` automatically for requests.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.