skyl / corpora

Corpora is a self-building corpus that can help build other arbitrary corpora
GNU Affero General Public License v3.0
2 stars 0 forks source link

feat(core): unique_together owner-corpus name, delete corpus, error handling #12

Closed skyl closed 3 weeks ago

skyl commented 3 weeks ago

PR Type

enhancement, bug fix, documentation


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
6 files
api.py
Add error handling and delete endpoint for corpus               

py/packages/corpora/api.py
  • Added error handling for unique constraint violations and validation
    errors.
  • Implemented a new endpoint to delete a corpus.
  • Enhanced response handling for corpus creation.
  • +36/-16 
    0005_alter_corpus_unique_together.py
    Enforce unique constraint on corpus name and owner             

    py/packages/corpora/migrations/0005_alter_corpus_unique_together.py
  • Added migration to enforce unique constraint on corpus name and owner.

  • +19/-0   
    models.py
    Add unique constraint to Corpus model                                       

    py/packages/corpora/models.py
  • Added unique constraint on name and owner fields in the Corpus model.
  • +1/-0     
    corpus.py
    Add error handling and delete command for corpus CLI         

    py/packages/corpora_cli/commands/corpus.py
  • Added error handling for corpus creation conflicts.
  • Implemented command to delete a corpus.
  • +28/-7   
    constants.py
    Add constant for corpus existence conflict message             

    py/packages/corpora_cli/constants.py - Added constant message for corpus existence conflict.
    +8/-0     
    corpora_api.py
    Add delete corpus API method and update response types     

    py/packages/corpora_client/api/corpora_api.py
  • Added API method for deleting a corpus.
  • Updated response types for corpus creation.
  • +250/-0 
    Tests
    1 files
    test_corpora_api.py
    Add test case for corpus deletion                                               

    py/packages/corpora_client/test/test_corpora_api.py - Added test case placeholder for corpus deletion.
    +7/-0     
    Configuration changes
    1 files
    .corpora.yaml
    Update configuration with name and URL                                     

    .corpora.yaml - Added `name` and `url` fields to configuration.
    +3/-0     
    Documentation
    3 files
    TODO.md
    Update TODO with note on unused imports                                   

    TODO.md - Added a note to remove unused imports.
    +2/-0     
    README.md
    Document delete corpus API method                                               

    py/packages/corpora_client/README.md - Documented the new delete corpus API method.
    +1/-0     
    CorporaApi.md
    Add documentation for delete corpus API method                     

    py/packages/corpora_client/docs/CorporaApi.md - Added documentation for the delete corpus API method.
    +80/-0   

    πŸ’‘ PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    github-actions[bot] commented 3 weeks ago

    PR Reviewer Guide πŸ”

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 πŸ”΅πŸ”΅πŸ”΅βšͺβšͺ
    πŸ§ͺ No relevant tests
    πŸ”’ No security concerns identified
    ⚑ Recommended focus areas for review

    Error Handling
    The new error handling for unique constraint violations and validation errors in the `create_corpus` function should be thoroughly tested to ensure it works as expected and provides meaningful error messages. CLI Error Handling
    The CLI command for deleting a corpus includes error handling for specific HTTP status codes. This should be tested to ensure it behaves correctly and provides clear feedback to the user.
    github-actions[bot] commented 3 weeks ago

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Validate that the uploaded tarball is not empty before processing ___ **Add a check to ensure that tarball_content is not empty before proceeding with
    processing to avoid unnecessary operations.** [py/packages/corpora/api.py [32]](https://github.com/skyl/corpora/pull/12/files#diff-a3bfbda31f4958bd5b403792dd85648527f5192b25bae26a5eb57ac7771e1be6R32-R32) ```diff tarball_content: bytes = await sync_to_async(tarball.read)() +if not tarball_content: + raise HttpError(400, "Uploaded tarball is empty.") ```
    Suggestion importance[1-10]: 8 Why: Adding a check to ensure the tarball is not empty before processing prevents unnecessary operations and potential errors, improving the robustness of the code.
    8
    Best practice
    Replace print statements with logging for better log management ___ **Consider using logging instead of print statements for better control over logging
    levels and outputs.** [py/packages/corpora/api.py [33]](https://github.com/skyl/corpora/pull/12/files#diff-a3bfbda31f4958bd5b403792dd85648527f5192b25bae26a5eb57ac7771e1be6R33-R33) ```diff -print(f"Received tarball: {len(tarball_content)} bytes") +logger.info(f"Received tarball: {len(tarball_content)} bytes") ```
    Suggestion importance[1-10]: 7 Why: Using logging instead of print statements is a best practice for better control over logging levels and outputs, which enhances maintainability and debugging in production environments.
    7
    Use sys.exit() instead of exit() for terminating the program ___ **Ensure that the exit(1) calls are replaced with sys.exit(1) for better clarity and
    to avoid potential issues in larger applications.** [py/packages/corpora_cli/commands/corpus.py [40]](https://github.com/skyl/corpora/pull/12/files#diff-c04094e69a69881444f8b97d9fee7e0d29683f5e062cb4d2cf4530bc08daedf7R40-R40) ```diff -exit(1) +sys.exit(1) ```
    Suggestion importance[1-10]: 6 Why: Replacing exit() with sys.exit() is a best practice for clarity and consistency, especially in larger applications, as it makes the termination of the program more explicit.
    6