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

It is possible to insert duplicate rsc_id, type and key entries into the identity table #3319

Open
mmzeeman opened this issue Mar 11, 2023 · 4 comments · May be fixed by #3320
Open

It is possible to insert duplicate rsc_id, type and key entries into the identity table #3319

mmzeeman opened this issue Mar 11, 2023 · 4 comments · May be fixed by #3320

Comments

@mmzeeman
Copy link
Member

Zotonic version

1.0.0-rc.15

OS / Browser version

MacOS / Safari

Steps to reproduce

Enter two entries in the identity table with the same rsc_id, type and key in parallel. (I'll try to catch it in a unit-test.)

Current behavior

Two entries are created.

Expected behavior

There should be one entry.

Config

N/A

@mmzeeman
Copy link
Member Author

The problem is that there is no constraint on the rsc_id, type and key in the identity table. The function inserting the entry does a sql select before inserting, trying to prevent this from happening. But the function is not in a transaction. Note that doing this in a transaction will also not prevent this from happening, because there is no constraint, so the database will happily add multiple entries.

@mworrell
Copy link
Member

mworrell commented Mar 11, 2023

Maybe just add a constraint and then match on the constraint error?

@mmzeeman
Copy link
Member Author

mmzeeman commented Mar 11, 2023

I'll first try to catch this in a unit-test. I was thinking about adding the constraint, and put the insertion itself in a transaction. I don't know how postgres will handle this.

@mmzeeman
Copy link
Member Author

It was possible to catch it in a unit-test. Added the constraint, which is working.

I will have to add code to update the schema of an existing database, but... there could be duplicate entries in the table. I'm a bit reluctant to automatically remove double entries.

Branch: https://github.com/zotonic/zotonic/tree/fix-3319

@mmzeeman mmzeeman linked a pull request Mar 11, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants