hasura / hasura/graphql-engine
Inconsistent session variable format when using _in VS _contained_in operators
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version:
CLI Version (for CLI related issue):
### Environment
### What is the current behaviour?
In our application, we have a session variable set as a JSON array like so:
Which we then use in some of our tables to set permissions using the `_contained_in` operator, like so:
The `value` column also being of JSON type, this works great.
However, we recently introduced another table, which contains a simple text column on which we tried to set similar permissions using `_in` operator. Queries against this table always return no result:
Upon taking a closer look at the documentation, it seems the `_in` operator expects a session variable using a slightly different format: `{123456, 789012, ... }` (essentially using `{}` instead of `[]`).
I tried switching to this format, which works for the second table, but fails when querying the first table with `malformed array literal`, making it seemingly impossible to mix and match these operators across our schema...
### What is the expected behaviour?
Ideally, both `_in` and `_contained_in` should accept the same session variable format.
### How to reproduce the issue?
1. Set a session variable as a JSON array
2. Set a table permission using `{"value":{"_contained_in":"x-hasura-user-groups"}}`
3. Set another table permission using `{"value":{"_in":"x-hasura-user-groups"}}`
### Screenshots or Screencast
### Please provide any traces or logs that could help here.
### Any possible solutions/workarounds you're aware of?
The only way I could think of working around this issue was to create a view and convert the text column to a JSON array with a single field using `jsonb_build_array` so we could continue to use `_contained_in`. This is fine for small tables, but far from ideal for larger ones:
```
CREATE OR REPLACE VIEW public.my_table_view
AS SELECT
jsonb_build_array(group) AS group,
...
FROM my_table;
```
### Keywords
Contributor guide
Research direction
Start by reproducing the permission rules from the issue with the JSON-array session variable, using both `_contained_in` and `_in`. Trace how each operator parses and compares the session variable value; done means both operators accept the same documented format without breaking the existing JSON-column behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgresql
- Domain
- api, authorization, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100