PolicyEngine / PolicyEngine/policyengine-api

`user_profile.py` create operation is not atomic

Open
#2,058 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
18
Forks
33
Avg merge
23h 40m
Merged PRs (30d)
22

Description

https://github.com/PolicyEngine/policyengine-api/blob/master/policyengine_api/endpoints/user_profile.py#L19-L57

  1. Does a select to see if a user already exists and then
  2. Does an insert if not.

This is not atomic so if I call it twice quickly I can get intermittently different behavior.

I am creating this issue to track the problem and come back to fix it later after addressing https://github.com/PolicyEngine/policyengine-api/issues/1989

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with issue 1989, which the author says must be addressed first, then inspect policyengine_api/endpoints/user_profile.py lines 19-57. Reproduce two quick create calls and observe the differing outcomes. Done means concurrent calls produce consistent behavior without the select-then-insert race.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.