aquametalabs / aquameta

Web development platform built entirely in PostgreSQL
GNU General Public License v3.0
1.1k stars 52 forks source link

endpoint: datum.js:339 type pg_ddl_command is a pseudotype #253

Closed erichanson closed 1 year ago

erichanson commented 1 year ago

This showed up when saving a bundle_doc row, then later disappeared. Appears to be a problem with meta.get_typedef(oid) ?

endpoint/0.3/relation/documentation/bundle_doc:1          Failed to load resource: the server responded with a status of 500 ()
datum.js:331 PATCH 500 Server Error
datum.js:338 /endpoint/0.3/relation/documentation/bundle_doc
eval @ datum.js:338
datum.js:339 type pg_ddl_command is a pseudotype
eval @ datum.js:339
datum.js:340 PL/pgSQL function meta.get_typedef(oid) line 19 at RAISE
PL/pgSQL assignment "q := '
            with inserted_row as (
                insert into ' || quote_ident(_schema_name) || '.' || quote_ident(_relation_name) ||
                case when args::text = '{}'::text then
                    ' default values '
                else
                    ' (' || (
                        select string_agg(quote_ident(json_object_keys), ',' order by json_object_keys)
                        from json_object_keys(args)

                    ) || ') values (' || (

                           select string_agg('
                                   case when json_typeof($3->' || quote_literal(json_object_keys) || ') = ''array'' then ((
                                            select ''{'' || string_agg(value::text, '', '') || ''}''
                                            from json_array_elements(($3->>' || quote_literal(json_object_keys) || ')::json)
                                        ))
                                        when json_typeof($3->' || quote_literal(json_object_keys) || ') = ''object'' then
                                            ($3->' || quote_literal(json_object_keys) || ')::text
                                        else ($3->>' || quote_literal(json_object_keys) || ')::text
                                   end::' || case when json_typeof((args->json_object_keys)) = 'object' then 'json::'
                                                  else ''
                                             end || c.type_name, ',
                                   '
                                   order by json_object_keys
                           ) from json_object_keys(args)
                           inner join meta.relation_column c
                                   on c.schema_name = _schema_name and
                                      c.relation_name = _relation_name and
                                      c.name = json_object_keys
                           left join meta.type t on c.type_id = t.id

                    ) || ') '
                end ||
                'returning *
            )
            select (''{
                "columns": ' || endpoint.columns_json(_schema_name, _relation_name, null::text[], null::text[]) || ',
                "pk":"' || coalesce(endpoint.pk_name(_schema_name, _relation_name), 'null') || '",
                "result": [{ "row": '' || row_to_json(inserted_row.*, true) || '' }]
            }'')::json
            from inserted_row
        '"
PL/pgSQL function row_insert(relation_id,json) line 20 at assignment
SQL statement "select 200, 'OK'::text, (select endpoint.row_insert(relation_id, post_data))::text, 'application/json'::text"
PL/pgSQL function endpoint.request(text,text,text,json,json) line 134 at RETURN QUERY
erichanson commented 1 year ago

Problem was with new unsupported types, pseudotypes and multirange, via meta.get_typedef(oid). The meta.type view blows up because when get_typedef finds a type it doesn't recognize, it throws an exception. See meta issue 15.