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

Failure on postgres when table name is domains #1028

Closed
tjikkun opened this issue Mar 28, 2024 · 10 comments
Closed

Failure on postgres when table name is domains #1028

tjikkun opened this issue Mar 28, 2024 · 10 comments
Assignees
Labels

Comments

@tjikkun
Copy link

tjikkun commented Mar 28, 2024

When creating a table in postgres with:

CREATE TABLE domains (
    id bigserial NOT NULL,
    post_id integer NOT NULL,
    message character varying(255) NOT NULL,
    category_id integer NOT NULL    
);

I get the following error

2024-03-28 15:43:40.045 UTC [66] ERROR:  column "domain_catalog" does not exist at character 13
2024-03-28 15:43:40.045 UTC [66] STATEMENT:  SELECT "id","domain_catalog","post_id","domain_schema","domain_name","message","data_type","category_id","character_maximum_length","character_octet_length","character_set_catalog","character_set_schema","character_set_name","collation_catalog","collation_schema","collation_name","numeric_precision","numeric_precision_radix","numeric_scale","datetime_precision","interval_type","interval_precision","domain_default","udt_catalog","udt_schema","udt_name","scope_catalog","scope_schema","scope_name","maximum_cardinality","dtd_identifier" FROM "domains"  WHERE "id" = $1

It seems it pulls in column names that are internal to postgres domains.

@mevdschee
Copy link
Owner

mevdschee commented Mar 28, 2024

Thank you for reporting this issue.

It seems it pulls in column names that are internal to postgres domains.

Yes, please report the postgres version you are running. Please also report other relevant versions (OS, PHP, etc).

NB: Did you run the tests?

@mevdschee mevdschee self-assigned this Mar 28, 2024
@mevdschee mevdschee added the bug label Mar 28, 2024
@tjikkun
Copy link
Author

tjikkun commented Mar 29, 2024

Sorry, not my best bug report ever :)
It was postgres 16.2 on debian (docker container) and PHP 8.3.
I found that the query from getTableColumnsSQL is the issue:

SELECT a.attname AS "COLUMN_NAME", case when a.attnotnull then 'NO' else 'YES' end as "IS_NULLABLE", pg_catalog.format_type(a.atttypid, -1) as "DATA_TYPE", case when a.atttypmod < 0 then NULL else a.atttypmod-4 end as "CHARACTER_MAXIMUM_LENGTH", case when a.atttypid != 1700 then NULL else ((a.atttypmod - 4) >> 16) & 65535 end as "NUMERIC_PRECISION", case when a.atttypid != 1700 then NULL else (a.atttypmod - 4) & 65535 end as "NUMERIC_SCALE", '' AS "COLUMN_TYPE" FROM pg_attribute a JOIN pg_class pgc ON pgc.oid = a.attrelid WHERE pgc.relname = 'domains' AND '' <> 'domains' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum;

This always returns data, even if you don't have a domains table (but when you do have that table this becomes an issue).

It did just ran the tests, they complete fine, but there is no domains table there :)

@mevdschee
Copy link
Owner

mevdschee commented Mar 29, 2024

but there is no domains table there :)

This domains thing is something new in PostgreSQL? Do you know what the pg_attribute and pg_class views look like causing this failure? Probably there is some internal table called domains, right?

mevdschee added a commit that referenced this issue Mar 29, 2024
mevdschee added a commit that referenced this issue Mar 29, 2024
@mevdschee
Copy link
Owner

Can you test the latest master?

@mevdschee
Copy link
Owner

Somehow the namespaces outside public where also evaluated. I restricted all reflection to the 'public' namespace, while I can imagine that people have other namespaces than public, so maybe it needs to be configurable.

@mevdschee
Copy link
Owner

mevdschee commented Mar 29, 2024

This shows the namespaces:

php-crud-api=# select distinct relnamespace::regnamespace::text from pg_class;
    relnamespace    
--------------------
 public
 pg_catalog
 pg_toast
 information_schema
(4 rows)

And the namespace that causes the problem:

php-crud-api=# select relnamespace::regnamespace::text from pg_class where relname = 'domains';
    relnamespace    
--------------------
 information_schema
(1 row)

Maybe the excluding condition should be:

relnamespace::regnamespace::text !~ '^pg_|information_schema'

What do you think?

mevdschee added a commit that referenced this issue Mar 29, 2024
mevdschee added a commit that referenced this issue Mar 29, 2024
@mevdschee
Copy link
Owner

Can you test the latest master?

@tjikkun
Copy link
Author

tjikkun commented Mar 29, 2024

Yes, latest master works, nice!

@mevdschee
Copy link
Owner

Released in v2.14.26

@mevdschee
Copy link
Owner

@tjikkun Dankjewel voor je bijdrage / Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants