litestar-org / litestar-fullstack

Litestar Fullstack Reference Application with React, Vite, SQLAlchemy, Docker, Task Queues, and more!
https://fullstack.litestar.dev/
MIT License
336 stars 56 forks source link

test: get_or_upsert concurrent use #179

Open FranzForstmayr opened 2 months ago

FranzForstmayr commented 2 months ago

Description

This PR acts as a reproducer for get_or_upsert raising IntegrityErrors for UniqueConstraint when sending multiple requests at once.

I added a UniqueConstraint to the user_account_role table which basically means, that one cannot have the same role multiple times.

In the controller I needed to remove the if statement, otherwise the get_or_upsert would not create anything in this case. However there's another bug in the original version, as created is not defined if the first condition is false.

The test contains 1 or 4 equal queries, two times in a row. When making a single request (which assigns the tag) the second request reports that the role was already assigned and succeeds. In case of 4 queries at the same time, only the first query succeeds, the remaining three fail.

This PR is not meant to get merged like this, but as a starting point for discussion.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud