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

fix: OPTIC-1420: Inner IDs are duplicated and counted wrong #6785

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

mcanu
Copy link
Contributor

@mcanu mcanu commented Dec 12, 2024

PR fulfills these requirements

  • Commit message(s) and PR title follows the format [fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made ex. fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors
  • Tests for the changes have been added/updated (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • Best efforts were made to ensure docs/code are concise and coherent (checked for spelling/grammatical errors, commented out code, debug logs etc.)
  • Self-reviewed and ran all changes on a local instance (for bug fixes/features)

Change has impacts in these area(s)

(check all that apply)

  • Product design
  • Backend (Database)
  • Backend (API)
  • Frontend

Describe the reason for change

There was an issue where the inner_id was duplicated when importing from the API. We identified the problem because a client was importing with two requests almost at the same time, causing a race condition when calculating the inner_id.

What does this fix?

Potential duplicate inner ids due to a race condition when importing from the API.

What is the new behavior?

Acquire lock on the project before calculating inner id. I tried to acquire the lock on the Tasks queryset, but when there weren't any tasks yet it wouldn't work, because it locks on the returned rows (empty the first time).

Does this change affect performance?

If there are multiple async imports for a same project at once like this case, they will eventually be committed sequentially. This is needed to ensure inner_id consistency.

Does this PR introduce a breaking change?

(check only one)

  • Yes, and covered entirely by feature flag(s)
  • Yes, and covered partially by feature flag(s)
  • No
  • Not sure (briefly explain the situation below)

What level of testing was included in the change?

(check all that apply)

  • e2e
  • integration
  • unit

For testing I created a small script to replicate this behavior. Running two separate worker processes is also needed, so they can consume each import job concurrently.

import json
from label_studio_sdk.client import LabelStudio

# Define the URL where Label Studio is accessible and the API key for your user account
LABEL_STUDIO_URL = ''
# API key is available at the Account & Settings > Access Tokens page in Label Studio UI
API_KEY = ''


# Connect to the Label Studio API and check the connection
ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY)

project_id = 7

with open('data/5400.json', 'r') as f:
    data_5400 = json.load(f)

with open('data/5500.json', 'r') as f:
    data_5500 = json.load(f)


ls.projects.import_tasks(id=project_id, request=data_5400)
ls.projects.import_tasks(id=project_id, request=data_5500)

Which logical domain(s) does this change affect?

Imports

@github-actions github-actions bot added the fix label Dec 12, 2024
Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for label-studio-docs-new-theme ready!

Name Link
🔨 Latest commit 7a8fc6a
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-docs-new-theme/deploys/6762fc1e1af9d30009260f75
😎 Deploy Preview https://deploy-preview-6785--label-studio-docs-new-theme.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for heartex-docs ready!

Name Link
🔨 Latest commit 7a8fc6a
🔍 Latest deploy log https://app.netlify.com/sites/heartex-docs/deploys/6762fc1e13e1e20008f0aa05
😎 Deploy Preview https://deploy-preview-6785--heartex-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.78%. Comparing base (2e360bc) to head (7a8fc6a).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6785   +/-   ##
========================================
  Coverage    76.77%   76.78%           
========================================
  Files          171      171           
  Lines        14021    14023    +2     
========================================
+ Hits         10765    10767    +2     
  Misses        3256     3256           
Flag Coverage Δ
pytests 76.78% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mcanu
Copy link
Contributor Author

mcanu commented Dec 16, 2024

/git merge develop

Workflow run
Successfully merged: 27 files changed, 842 insertions(+), 57 deletions(-)

@mcanu
Copy link
Contributor Author

mcanu commented Dec 18, 2024

/git merge develop

Workflow run
Successfully merged: create mode 100644 web/libs/datamanager/src/components/MainView/GridView/ImagePreview.tsx

label_studio/tasks/serializers.py Outdated Show resolved Hide resolved
@mcanu mcanu requested a review from makseq December 18, 2024 16:45
@mcanu mcanu merged commit bd3498d into develop Dec 18, 2024
44 checks passed
@makseq makseq deleted the fb-optic-1420 branch December 18, 2024 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants