InsertAsync on Postgres returns the wrong identifier
See original GitHub issueBug Description
I have a table in Postgres with the following structure:
which is then mapped to the following model:
since upgrading to verison 1.13.0 InsertAsync has started returning an empty GUID for the identifier:
It works fine if the account used to connect to the database is a member of the super user role or is the owner of the table but fails when I use a normal user account that is not the owner which makes me think it might have something to do with information schema permissions. The same code worked using the previous version of RepoDb.
Interestingly the synchronous version of Insert does not seem to be effected.
Additional information:
I believe RepoDb is executing the following SQL internally to get informaiton about the table:
SELECT c.column_name , Cast(( CASE
WHEN c.column_name = tmp.column_name THEN 1 ELSE 0 END) AS BOOLEAN) AS isprimary , CASE
WHEN c.is_identity = 'YES' OR position('NEXTVAL' IN upper(c.column_default)) >= 1 THEN true
ELSE false
END AS isidentity , cast(c.is_nullable AS boolean) AS isnullable , c.data_type AS datatype , CASE
WHEN c.column_default IS NOT NULL THEN true
ELSE false
END AS hasdefaultvalue
FROM information_schema.columns c
LEFT JOIN ( SELECT c.table_schema , c.table_name , c.column_name , c.column_default
FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage AS ccu
using (constraint_schema, constraint_name) JOIN information_schema.columns AS c
ON c.table_schema = tc.constraint_schema
AND tc.table_name = c.table_name
AND ccu.column_name = c.column_name
WHERE tc.constraint_type = 'PRIMARY KEY' ) tmp
ON tmp.table_schema = c.table_schema
AND tmp.table_name = c.table_name
AND tmp.column_name = c.column_name
WHERE c.table_name = 'asset_type'AND c.table_schema = 'public';`
when I execute this as a superuser I get:
but when I execute the same query as a normal user i get the following results:
Issue Analytics
- State:
- Created 7 months ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top GitHub Comments
@mikependon I’ve also faced the same issue. As @grofit said, it is related to the user’s table/column ownership only.
The issue is occurring, when using a DB user (who is not a DB Owner) having only read/write rights on specific tables. This is because of information_schema.column view. It shows only those columns that the current user has access to (by way of being the owner or having some privilege). Documentation
In the end, we directly use the user who was DB Owner to resolve the issue as we didn’t have much time to investigate further.
In the latest version, that class and also to the other extended libraries (i.e.: RepoDb.SqlServer, RepoDb.MySql, etc), they were all marked as obsolete already.