-
Notifications
You must be signed in to change notification settings - Fork 126
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
InsertAsync on Postgres returns the wrong identifier #1131
Comments
It sounds to me that as per your post, this issue is not happening in an earlier version of the library. In the latest version, we have introduced the KeyColumnReturnBehavior that might had impact this case, though our Integration Tests has succeed. Would you be able to play around with that enumeration during startup? |
From what I can tell the key column return behaviour doesn't seem to effect the issue as its not correctly working out if its a primary key correctly so regardless of which one is set it always seems to fail in resolving what the primary key is from the DB side so just inserts an empty value for the data type. I am not sure if this is a postgres only issue and while you do have integration tests it seems like you are using a single user which potentially has full permissions on each table so the problem wouldn't exhibit (from what I can tell). I don't know enough about how postgres internally works, so not sure if our user is missing privileges that stops them getting the correct response for For us the locked down user has permissions like this: GRANT ALL PRIVILEGES ON DATABASE <your-dbname> TO <your-user>;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA <your-schema> TO <your-user>;
GRANT DELETE, INSERT, SELECT, UPDATE ON <your-table> TO <your-user>; |
Hi Gents, first of all, thanks for reporting this issue. We have investigated this issue and ...
We failed to replicate your claims about this issue working with the old version of the library. Would you be able to share which version it is working? Unfortunately, our last release has major changes which limit us to recover the old code of the library. And since we cannot recover, we cannot also do replicate the issue codebase-wise. We urged you use the latest version moving forward, of course, please help us resolve this issue by supplying us the necessary information to replicate or "how to best fix this". On the other hand, @grofit.
We followed your steps and TBH, we could not replicate the issue you mentioned about super user and normal user. We both create SUPER and Non-SUPER user and limit the privilege of the other one, and we failed it there. (See the attached project) There, in the attached project, we simply created a project and created the corresponding user and schema/table on our development environment and call the method in discussed. In case you would like to test your claim and do not want to be blocked while we are solving this issue, would you be able to inject your own customized
DbHelperMapper.Add<NpgsqlConnection>(new CustomizedPostgreSqlDbHelper(), true); It must be done "AFTER" the initialization method below. //GlobalConfiguration.Setup().UsePostgreSql(); // RepoDb.PostgreSql (v1.13.0)
PostgreSqlBootstrap.Initialize(); // RepoDb.PostgreSql (v1.1.5) To end with, please be mindful that it has been stated on our limitation page that the following are limitations.
The rationale behind is because the library is "by designed" only return single value, and that single value is the identity column (auto-increment). It cannot accommodate the latest values generated by the DB/Table after the insertion/update/merging of the data towards it. |
In the latest version var options = new GlobalConfigurationOptions()
{
KeyColumnReturnBehavior = KeyColumnReturnBehavior.Identity
};
GlobalConfiguration.Setup(options).UsePostgreSql(); Such behavior will behave like it was in the past. Setting the We might consider this as |
Thank you so much for looking into this, I think this may totally be our fault as we had not moved over to use the newer If that is the problem is there any way to indicate to devs that the old approach is obsolete or even remove it entirely if that is no longer the way to setup ( |
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. |
Ok so thank you again for verifying this, I have moved the code over to use the newer approach but I still see same failures on insertion. On my local system it works fine and correctly inserts the Ids (some Ids are using identity, some are manually set) but either way it all works perfectly fine using the older bootstrap approach or the newer global configuration one. However when I push the build out to another environment the same code fails there, so I fear there must be something different that I'm missing in terms of how things are setup on my local vs server setups. I know locally im running a docker provisioned postgres v13, whereas on the server in question I think its using postgres 12 but the postgres on the server is setup externally to us, so not entirely sure what is different, will see if I can find some info, or maybe @monoculture has some more information from their investigations. |
Upon conferring it looks like it may be down to the "table owner" so when you did your test was one user the table owner and the other user was not? as that seems to be the deciding factor (from what we can tell) is going to indicate if it gets a true or a false for the |
@grofit - for you to not get blocked and have a controllability, can you able to override this for now until we rectified the problem? As I stated in the above comment, you can follow the step below
If you did this, we are happy to get the code from you on how did you solve this 2 both user. Looking forward |
Hey, sorry for delay. We had a chat and for the moment to unblock us we have just made the current user the table owner and it has gone away, which we did via following query per table: ALTER TABLE <your_table> OWNER TO <your_user>; This has stopped the issue happening on the environment so for reproduction on your side you can probably just make another user the table owner and it should happen. As I said before I don't know enough around the innards of Postgres to be able to ascertain why this is an issue, as maybe other DBs allow multiple table owners or different ways of handling it, but either way we have worked around it for now and at least we know the root cause. |
@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. |
Bug 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:
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:
The text was updated successfully, but these errors were encountered: