ITISFoundation / osparc-simcore

🐼 osparc-simcore simulation framework
https://osparc.io
MIT License
44 stars 26 forks source link

🐛 Fixes api-keys unique constraint violation (🚨) #5890

Closed pcrespov closed 1 month ago

pcrespov commented 1 month ago

What do these changes do?

While starting a jupyter (in master), the variable substitution component triggers a callback to auto-generate a valid api-key for the current user. This callback raises

 File "/home/scu/.venv/lib/python3.10/site-packages/simcore_service_director_v2/modules/osparc_variables/_api_auth.py", line 40, in _get_or_create_data
    return await create_api_key_and_secret(
  File "/home/scu/.venv/lib/python3.10/site-packages/simcore_service_director_v2/modules/osparc_variables/_api_auth_rpc.py", line 28, in create_api_key_and_secret
    result = await rpc_client.request(
  File "/home/scu/.venv/lib/python3.10/site-packages/servicelib/rabbitmq/_client_rpc.py", line 96, in request
    return await asyncio.wait_for(awaitable, timeout=timeout_s)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/home/scu/.venv/lib/python3.10/site-packages/aio_pika/patterns/rpc.py", line 413, in call
    return await future
servicelib.rabbitmq._errors.RPCServerError: While running method 'create_api_keys' raised 'psycopg2.errors.UniqueViolation': 'duplicate key value violates unique constraint "display_name_userid_uniqueness"
DETAIL:  Key (display_name, user_id)=(__auto_c52f362c-10cc-55b9-9539-82d97856bf06, 530) already exists.
'

Manual exploratory testing suggested that this error is produced by a race condition when executing get and create operations. Note that get_or_create operation was implemented in the directorv2 calls to get and create function are connected via RPC -> service -> repo.

Related issue/s

How to test

Driving tests

cd services/web/server
make install-dev
pytest -vv tests/unit -k test_get_or_create_api_key

Dev-ops checklist

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 95.34884% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 85.1%. Comparing base (cafbf96) to head (d5bed17). Report is 232 commits behind head on master.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890/graphs/tree.svg?width=650&height=150&src=pr&token=h1rOE8q7ic&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) ```diff @@ Coverage Diff @@ ## master #5890 +/- ## ========================================= + Coverage 84.5% 85.1% +0.5% ========================================= Files 10 561 +551 Lines 214 28228 +28014 Branches 25 205 +180 ========================================= + Hits 181 24032 +23851 - Misses 23 4145 +4122 - Partials 10 51 +41 ``` | [Flag](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [integrationtests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `63.6% <46.5%> (?)` | | | [unittests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `86.4% <95.3%> (+1.8%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [...rc/simcore\_service\_director\_v2/core/application.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fdirector-v2%2Fsrc%2Fsimcore_service_director_v2%2Fcore%2Fapplication.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvZGlyZWN0b3ItdjIvc3JjL3NpbWNvcmVfc2VydmljZV9kaXJlY3Rvcl92Mi9jb3JlL2FwcGxpY2F0aW9uLnB5) | `96.2% <100.0%> (ø)` | | | [...s/dynamic\_sidecar/scheduler/\_core/\_events\_utils.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fdirector-v2%2Fsrc%2Fsimcore_service_director_v2%2Fmodules%2Fdynamic_sidecar%2Fscheduler%2F_core%2F_events_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvZGlyZWN0b3ItdjIvc3JjL3NpbWNvcmVfc2VydmljZV9kaXJlY3Rvcl92Mi9tb2R1bGVzL2R5bmFtaWNfc2lkZWNhci9zY2hlZHVsZXIvX2NvcmUvX2V2ZW50c191dGlscy5weQ==) | `92.6% <ø> (ø)` | | | [...\_director\_v2/modules/osparc\_variables/\_api\_auth.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fdirector-v2%2Fsrc%2Fsimcore_service_director_v2%2Fmodules%2Fosparc_variables%2F_api_auth.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvZGlyZWN0b3ItdjIvc3JjL3NpbWNvcmVfc2VydmljZV9kaXJlY3Rvcl92Mi9tb2R1bGVzL29zcGFyY192YXJpYWJsZXMvX2FwaV9hdXRoLnB5) | `100.0% <100.0%> (ø)` | | | [...ver/src/simcore\_service\_webserver/api\_keys/\_api.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fweb%2Fserver%2Fsrc%2Fsimcore_service_webserver%2Fapi_keys%2F_api.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvd2ViL3NlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX3dlYnNlcnZlci9hcGlfa2V5cy9fYXBpLnB5) | `100.0% <100.0%> (ø)` | | | [...rver/src/simcore\_service\_webserver/api\_keys/\_db.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fweb%2Fserver%2Fsrc%2Fsimcore_service_webserver%2Fapi_keys%2F_db.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvd2ViL3NlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX3dlYnNlcnZlci9hcGlfa2V5cy9fZGIucHk=) | `95.0% <100.0%> (ø)` | | | [...ector\_v2/modules/osparc\_variables/\_api\_auth\_rpc.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fdirector-v2%2Fsrc%2Fsimcore_service_director_v2%2Fmodules%2Fosparc_variables%2F_api_auth_rpc.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvZGlyZWN0b3ItdjIvc3JjL3NpbWNvcmVfc2VydmljZV9kaXJlY3Rvcl92Mi9tb2R1bGVzL29zcGFyY192YXJpYWJsZXMvX2FwaV9hdXRoX3JwYy5weQ==) | `76.9% <66.6%> (ø)` | | | [...ver/src/simcore\_service\_webserver/api\_keys/\_rpc.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890?src=pr&el=tree&filepath=services%2Fweb%2Fserver%2Fsrc%2Fsimcore_service_webserver%2Fapi_keys%2F_rpc.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvd2ViL3NlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX3dlYnNlcnZlci9hcGlfa2V5cy9fcnBjLnB5) | `96.0% <80.0%> (ø)` | | ... and [564 files with indirect coverage changes](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5890/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)
sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.2% Duplication on New Code

See analysis details on SonarCloud