hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.77k forks source link

cannot track functions on schema that begin with "pg" #3830

Open nicolateral opened 4 years ago

nicolateral commented 4 years ago

Docker images hasura/graphql-engine:v1.1.0-beta.2 postgres:11.3

Issue It is the first time I try to track a function on non-public schema. I have this function "item_search" on schema "pgw" :

CREATE OR REPLACE FUNCTION pgw.item_search (search text)
    RETURNS SETOF pgw.item
    LANGUAGE sql
    STABLE
AS $BODY$
    WITH RECURSIVE sel AS (
        SELECT * FROM pgw.item WHERE to_tsvector(COALESCE(code, '') || ' ' || name) @@ websearch_to_tsquery($1)
        UNION
        SELECT rel.* FROM pgw.item AS rel, sel WHERE rel.id = sel.parent_id
    )
    SELECT * FROM sel;
$BODY$;

This function does not appears in the console.

I tried to track this function using the API :

Request (track_function:v1)

POST http://localhost:8080/v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type": "track_function",
    "args": {
        "schema": "pgw",
        "name": "item_search"
    }
}

Request (track_function:v2)

POST http://localhost:8080/v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type": "track_function",
    "version": 2,
    "args": {
        "function": {
            "schema": "pgw",
            "name": "item_search"
        }
    }
}

Response

HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Date: Tue, 04 Feb 2020 13:02:51 GMT
Server: Warp/3.2.27
Content-Type: application/json; charset=utf-8

{
  "internal": [
    {
      "definition": {
        "schema": "pgw",
        "name": "item_search"
      },
      "reason": "in function \"pgw.item_search\": no such function exists in postgres : \"pgw.item_search\"",
      "type": "function"
    }
  ],
  "path": "$.args",
  "error": "in function \"pgw.item_search\": no such function exists in postgres : \"pgw.item_search\"",
  "code": "constraint-violation"
}

When I create this function on public schema (changing its name pgp.item_search to pgp_item_search), this works fine, as usual (the function appears in console and can be tracked using the API).

rakeshkky commented 4 years ago

Hi @nicodinh ,

I'm unable to reproduce the issue by creating a custom SQL function in non-public schema.

Please execute the following SQL query and comment down the results;

select * from hdb_catalog.hdb_function_info_agg where function_name = 'item_search';
nicolateral commented 4 years ago

Hi @rakeshkky ,

Please execute the following SQL query and comment down the results;

select * from hdb_catalog.hdb_function_info_agg where function_name = 'item_search';

This query returns an empty resultset.

The function does not appears in hdb_catalog.hdb_function_info_agg. Can you paste in reply a function definition that is supposed to works ? I will tell you if it works in my pgwschema.

nicolateral commented 4 years ago

@rakeshkky , I just tried to create a fake schema my_schema in the console and then create my function in my_schema. This works ... still investigate why this does not works under pgw.

tirumaraiselvan commented 4 years ago

@nicolateral Is this still a problem?

nicolateral commented 4 years ago

@tirumaraiselvan hi, yes. I'm currently using

hasura/graphql-engine:v1.1.0 postgres:11.3

It seems that I cannot track functions on schema that begin with "pg". I tried some schema names ("pgw", "pgx" ...) and it does not works. But it works with ("prg", "my_schema").

tirumaraiselvan commented 4 years ago

@nicolateral Thanks for the report. I could reproduce this at my end as well. Changing the title to reflect the bug.

The issue has both server and console components:

Server: track_function throws an error on schemas starting with "pg". Console: Does not list track-able functions on schemas starting with "pg".

rikinsk commented 4 years ago

@tirumaraiselvan I think the console issue would be solved with the server fix as well. the console uses data in the hdb_catalog.hdb_function_agg view to list the functions