openml / server-api

Python-based server
https://openml.github.io/server-api/
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Change/dataset/tag #202

Closed PGijsbers closed 1 week ago

PGijsbers commented 1 week ago

The tag element is now always a list, regardless of the number of elements.

TODO: Update migration documentation.

Summary by Sourcery

Ensure the tag element is always returned as a list in the dataset tagging API, refactor error handling with helper functions, and update tests to reflect these changes.

Enhancements:

Tests:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This pull request modifies the dataset tagging functionality to consistently return tags as a list, refactors error handling, and updates related tests. The changes primarily affect the tag_dataset function in the datasets.py file and corresponding test files.

Sequence diagram for dataset tagging process

sequenceDiagram
    actor User
    participant DatasetTagging
    participant Database
    participant ErrorFactory

    User->>DatasetTagging: Request to tag dataset
    DatasetTagging->>Database: Get existing tags
    Database-->>DatasetTagging: Return tags
    DatasetTagging->>ErrorFactory: Check if tag exists
    ErrorFactory-->>DatasetTagging: Return error if exists
    DatasetTagging->>ErrorFactory: Check user authentication
    ErrorFactory-->>DatasetTagging: Return error if authentication fails
    DatasetTagging->>Database: Tag dataset
    DatasetTagging-->>User: Return updated tag list

Class diagram for updated error handling in dataset tagging

classDiagram
    class DatasetTagging {
        +tag_dataset(data_id, tag, user, expdb_db) dict
    }
    class HTTPException {
        +status_code: HTTPStatus
        +detail: dict
    }
    class ErrorFactory {
        +create_authentication_failed_error() HTTPException
        +create_tag_exists_error(data_id, tag) HTTPException
    }
    DatasetTagging --> HTTPException
    DatasetTagging --> ErrorFactory
    ErrorFactory --> HTTPException

File-Level Changes

Change Details Files
Modify tag_dataset function to always return tags as a list
  • Remove conditional logic for single vs. multiple tags
  • Update return statement to always include tags in a list format
  • Refactor error handling into separate functions
src/routers/openml/datasets.py
Refactor error handling in tag_dataset function
  • Create create_tag_exists_error function for handling existing tag errors
  • Create create_authentication_failed_error function for handling authentication errors
  • Replace inline error raising with calls to new error handling functions
src/routers/openml/datasets.py
Update dataset tagging tests to accommodate new list format
  • Modify test assertions to expect tags in list format
  • Add dataset_id 131 to parametrized test cases
  • Improve error handling and skipping logic in test_dataset_tag_response_is_identical
  • Introduce nested_remove_single_element_list function (implementation not shown in diff)
tests/routers/openml/migration/datasets_migration_test.py
tests/routers/openml/dataset_tag_test.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (main@e23f74b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...outers/openml/migration/datasets_migration_test.py 83.33% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #202 +/- ## ======================================= Coverage ? 91.66% ======================================= Files ? 49 Lines ? 1823 Branches ? 144 ======================================= Hits ? 1671 Misses ? 109 Partials ? 43 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.