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

server: API throws error when we use column with custom data type in row level permissions (MSSQL server) #10240

Open
meetzaveri opened this issue May 15, 2024 · 0 comments
Labels
k/bug Something isn't working

Comments

@meetzaveri
Copy link
Member

Version Information

Server Version: 2.39.1

Environment

Cloud

What is the current behaviour?

Currently, if we setup SELECT (row) permissions in a table which consists of a column with custom data type wrapped behind tinyint data type, it will throw below error:

{
      "message": "database query error",
      "extensions": {
        "path": "$",
        "code": "unexpected"
      }
}

In my case , I had a table with column name id and it's data type was bCompany which was in turn a custom data type wrapped behind tinyint data type.

What is the expected behaviour?

Well I am not sure what the real issue here it be. It might be

  • not able to handle custom data type
  • not able to parse the real data type behind custom data type in permissions logic
  • not able to support tinyint data type column in permission logic

Expected behavior can be one of the below

  • If it's a limitation, we should alert user in permissions UI suggest that we don't support custom data type column
  • If it's not a limitation, we can identify root cause and provide a fix.

How to reproduce the issue?

I created custom data type:

CREATE TYPE bCompany
FROM tinyint;

Here's the tenant table schema

id: bCompany, primary key, unique
first_name: text
last_name: text
age: tinyint
phone: text, nullable

Note that bCompany is custom datatype created from tinyint type.

I setup row SELECT permissions as

{"id":{"_eq":"X-Hasura-Tenant-Id"}}

And then I performed the query which produced the above mentioned error as stated in 3rd section

query getTenants {
  raw:tenant {
    age
    first_name
    id
  }
}

my request headers

x-hasura-role: user
x-hasura-tenant-id: 2

Any possible solutions/workarounds you're aware of?

One such workaround as advised from the engineering team is to create a view off that table with that column casted to some different data type like VARCHAR.

I created view. Note that I used CAST function from MSSQL server to cast customd data type column into VARCHAR in new updated view.

CREATE VIEW tenant_info_view AS
SELECT 
    CAST(id AS VARCHAR(100)) AS tenant_id,
    first_name,
    phone
FROM tenant;

Now you can use that tenant_id in permissions, since you'll need to setup permissions in view rather than in the original table.

Keywords

mssql tinyint permissions custom

@meetzaveri meetzaveri added the k/bug Something isn't working label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant