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: LEAP-1805: revisit S3 exceptions behavior #7015

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

jombooth
Copy link
Contributor

@jombooth jombooth commented Feb 3, 2025

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

(link to issue, supportive screenshots etc.)

What does this fix?

(if this is a bug fix)

What is the new behavior?

(if this is a breaking or feature change)

What is the current behavior?

(if this is a breaking or feature change)

What libraries were added/updated?

(list all with version changes)

Does this change affect performance?

(if so describe the impacts positive or negative)

Does this change affect security?

(if so describe the impacts positive or negative)

What alternative approaches were there?

(briefly list any if applicable)

What feature flags were used to cover this change?

(briefly list any if applicable)

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

Which logical domain(s) does this change affect?

(for bug fixes/features, be as precise as possible. ex. Authentication, Annotation History, Review Stream etc.)

@github-actions github-actions bot added the fix label Feb 3, 2025
Copy link

netlify bot commented Feb 3, 2025

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit bc5a19e
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-docs-new-theme/deploys/67a15477810ddd0008dd244e

Copy link

netlify bot commented Feb 3, 2025

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit bc5a19e
🔍 Latest deploy log https://app.netlify.com/sites/heartex-docs/deploys/67a154774940b60008de54be

Copy link
Member

@makseq makseq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a simple test there?

import pytest
from unittest.mock import patch, MagicMock
from your_module import catch_and_reraise_from_none, S3StorageError

def test_catch_and_reraise_from_none_with_untrusted_domain():
    class TestClass:
        s3_endpoint = 'http://untrusted-domain.com'
    
    instance = TestClass()
    
    @catch_and_reraise_from_none
    def function_to_test(self):
        raise Exception("Original Exception")
    
    with patch('your_module.extractor.extract_urllib') as mock_extract:
        mock_extract.return_value.registered_domain = 'untrusted-domain.com'
        with patch('your_module.settings.S3_TRUSTED_STORAGE_DOMAINS', ['trusted-domain.com']):
            with pytest.raises(S3StorageError) as excinfo:
                function_to_test(instance)
            assert "Debugging info is not available for s3 endpoints on domain: untrusted-domain.com" in str(excinfo.value)

def test_catch_and_reraise_from_none_with_trusted_domain():
    class TestClass:
        s3_endpoint = 'http://trusted-domain.com'
    
    instance = TestClass()
    
    @catch_and_reraise_from_none
    def function_to_test(self):
        raise Exception("Original Exception")
    
    with patch('your_module.extractor.extract_urllib') as mock_extract:
        mock_extract.return_value.registered_domain = 'trusted-domain.com'
        with patch('your_module.settings.S3_TRUSTED_STORAGE_DOMAINS', ['trusted-domain.com']):
            with pytest.raises(Exception) as excinfo:
                function_to_test(instance)
            assert "Original Exception" in str(excinfo.value)

logger.error(f'Exception from unrecognized S3 domain: {e}', exc_info=True)
raise S3StorageError(
f'Debugging info is not available for s3 endpoints on domain: {domain}. '
'Please contact your administrator if you require detailed debugging info for this domain.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would point users to LS devops team or something like this. Because administrator is a role from LS org.

Suggested change
'Please contact your administrator if you require detailed debugging info for this domain.'
'Please contact your Label Studio devops team if you require detailed debugging info for this domain.'

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

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

Project coverage is 76.93%. Comparing base (06eeb5c) to head (bc5a19e).

Files with missing lines Patch % Lines
label_studio/io_storages/s3/utils.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7015      +/-   ##
===========================================
+ Coverage    76.91%   76.93%   +0.01%     
===========================================
  Files          175      175              
  Lines        14167    14192      +25     
===========================================
+ Hits         10896    10918      +22     
- Misses        3271     3274       +3     
Flag Coverage Δ
pytests 76.93% <92.30%> (+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.

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