graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Permissions: TypeError: Cannot read properties of null (reading 'schema')

Open ipb26 opened this issue 2 years ago • 6 comments

Version Information

Server Version: v2.30.1

Environment

OSS

What is the current behaviour?

Getting this error when I try to reference a specific relation in the permissions json. As soon as i type {"relation":{}} in the permissions json the page crashes and I get this. This seems to happen only on relationships based on more than one column.

TypeError: Cannot read properties of null (reading 'schema') at o (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/main.4b70ba0818cc58d1.js.gz:50:349934) at o (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/main.4b70ba0818cc58d1.js.gz:50:349436) at https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/main.4b70ba0818cc58d1.js.gz:50:350065 at Array.forEach () at PermissionBuilder.loadMissingSchemas (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/main.4b70ba0818cc58d1.js.gz:50:350044) at PermissionBuilder.componentDidUpdate (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/main.4b70ba0818cc58d1.js.gz:50:349143) at bs (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/vendor.e7f457e1bd17861a.js.gz:112:1782476) at Pl (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/vendor.e7f457e1bd17861a.js.gz:112:1799191) at t.unstable_runWithPriority (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/vendor.e7f457e1bd17861a.js.gz:112:3819092) at Ga (https://graphql-engine-cdn.hasura.io/console/assets/channel/stable/v2.30/vendor.e7f457e1bd17861a.js.gz:112:1741328)

How to reproduce the issue?

  1. Create a composite foreign key.
  2. Create a relation based on that key.
  3. Try to reference that relation in the permissions "custom check" for any action.

Screenshots or Screencast

image

Please provide any traces or logs that could help here.

There are no errors in the server log.

Any possible solutions/workarounds you're aware of?

No

Keywords

Just the error message, found no results.

ipb26 avatar Aug 02 '23 17:08 ipb26

Exact same problem on v2.23.0 and v2.35.1 image

This only happens with composite foreign keys when creating a permission and reference to this composite key. If you do not use foreign keys and create relationships manually, this does not happen. But that is not good when I can't use foreign keys because of this.

ProudKingLion avatar Nov 18 '23 13:11 ProudKingLion

👍 Same thing over here!

miking-the-viking avatar Jul 18 '24 21:07 miking-the-viking

👍 Same thing over here!

panchaldeep009 avatar Jul 19 '24 14:07 panchaldeep009

any workaround?

iamolegga avatar Oct 09 '24 20:10 iamolegga

Manually change the way your relationships are specified in your metadata to this format @iamolegga

            "using": {
              "manual_configuration": {
                "column_mapping": {
                  "company_id": "company_id",
                  "location_id": "id"
                },
                "insertion_order": null,
                "remote_table": {
                  "name": "locations",
                  "schema": "public"
                }
              }
            }

ipb26 avatar Oct 16 '24 20:10 ipb26

@sampbarrow thanks, I've solved this temporary with creating generated columns for both tables, yucky

iamolegga avatar Oct 16 '24 21:10 iamolegga

Hey @sampbarrow, we have fixed this issue. The fix will be available from v2.45. You can now create permissions that involve composite foreign keys in your relationship definitions. Let me know if you run into any issues!

Varun-Choudhary avatar Nov 13 '24 12:11 Varun-Choudhary