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

API Refactoring #20

Merged
merged 30 commits into from
May 31, 2024
Merged

API Refactoring #20

merged 30 commits into from
May 31, 2024

Conversation

GabrielBarberini
Copy link
Collaborator

@GabrielBarberini GabrielBarberini commented May 22, 2024

Improves overall code with emphasis in better error handling and db utilization

Summary by CodeRabbit

  • New Features

    • Enhanced logging and error handling across flight, motor, rocket, and environment controllers and repositories.
    • Introduced new methods for fetching, creating, updating, and simulating flights, motors, and rockets.
    • Added thread-safe singleton pattern for repository initialization.
  • Refactor

    • Renamed methods and updated method signatures for better clarity and consistency.
    • Refactored property definitions and method implementations to improve code readability and maintainability.
  • Bug Fixes

    • Improved error reporting and handling to ensure data consistency.

Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

The recent updates focus on enhancing logging, error handling, and method consistency across several controllers and repositories. These changes include renaming methods for clarity, adding new properties and methods, and refining existing functionalities. The goal is to improve code readability, maintainability, and robustness in handling flight, motor, rocket, and environment operations.

Changes

Files Change Summary
lib/controllers/flight.py Added logging and error handling, renamed methods, updated method signatures, added properties and setters.
lib/controllers/motor.py Added logging and error handling, renamed methods, updated method signatures, added properties and setters.
lib/controllers/rocket.py Added logging and error handling, renamed methods, updated method signatures, added properties and setters.
lib/repositories/environment.py Refactored EnvRepository, added new method fetch_env, renamed methods, updated properties.
lib/repositories/flight.py Added logging, refactored FlightRepository, added new method fetch_flight, renamed methods, updated properties.
lib/repositories/motor.py Added logging, refactored MotorRepository, added new method fetch_motor, renamed methods, updated properties.
lib/repositories/repo.py Introduced thread-safe singleton pattern, added new methods for connection management, updated properties.
lib/repositories/rocket.py Added logging, refactored RocketRepository, added new method fetch_rocket, renamed methods, updated properties.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant FlightController
    participant FlightRepository
    participant Logger

    Client->>FlightController: get_flight_by_id(flight_id)
    FlightController->>Logger: log("Fetching flight by id")
    FlightController->>FlightRepository: get_flight_by_id(flight_id)
    FlightRepository->>FlightController: return Flight
    FlightController->>Client: return Flight
Loading

Poem

In the code where rockets soar,
Logs and errors, we explore.
Methods renamed, clear and bright,
Controllers guide each flight.
Repositories hold the key,
To data's vast and endless sea.
With these changes, swift and grand,
Our code will truly stand! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 15

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 297f6d8 and 803f0db.
Files ignored due to path filters (1)
  • lib/data/engines/Cesaroni_7450M2505-P.csv is excluded by !**/*.csv
Files selected for processing (24)
  • lib/init.py (1 hunks)
  • lib/api.py (2 hunks)
  • lib/controllers/init.py (1 hunks)
  • lib/controllers/environment.py (12 hunks)
  • lib/controllers/flight.py (5 hunks)
  • lib/controllers/motor.py (6 hunks)
  • lib/controllers/rocket.py (5 hunks)
  • lib/models/aerosurfaces.py (1 hunks)
  • lib/models/environment.py (1 hunks)
  • lib/models/flight.py (1 hunks)
  • lib/models/motor.py (5 hunks)
  • lib/models/rocket.py (2 hunks)
  • lib/repositories/init.py (1 hunks)
  • lib/repositories/environment.py (3 hunks)
  • lib/repositories/flight.py (1 hunks)
  • lib/repositories/motor.py (1 hunks)
  • lib/repositories/repo.py (1 hunks)
  • lib/repositories/rocket.py (1 hunks)
  • lib/routes/environment.py (5 hunks)
  • lib/routes/flight.py (5 hunks)
  • lib/routes/motor.py (3 hunks)
  • lib/routes/rocket.py (3 hunks)
  • lib/secrets.py (1 hunks)
  • pyproject.toml (3 hunks)
Files not reviewed due to errors (1)
  • lib/controllers/flight.py (no review received)
Files skipped from review due to trivial changes (4)
  • lib/controllers/init.py
  • lib/models/aerosurfaces.py
  • lib/repositories/init.py
  • lib/routes/environment.py
Additional comments not posted (64)
lib/__init__.py (1)

12-15: Good implementation of error formatting.

The parse_error function enhances error message readability by formatting exceptions into a cleaner, single-line string. This is beneficial for logging and debugging.

lib/secrets.py (1)

16-20: Well-implemented method for fetching secrets.

The get_secret method correctly prioritizes .env values and falls back to OS environment variables, adhering to best practices for application configuration management.

pyproject.toml (1)

Line range hint 22-59: Review disabled pylint checks to ensure alignment with coding standards.

The added keywords are appropriate and enhance project discoverability. However, the extensive list of disabled pylint checks should be reviewed to ensure it aligns with your team's coding standards and does not suppress important warnings.

lib/models/rocket.py (1)

47-49: Proper use of private attribute exposure.

The rocket_option property is a good example of exposing a private attribute through a property, adhering to encapsulation principles.

lib/repositories/repo.py (3)

15-20: The singleton pattern implementation using a lock is correctly done, ensuring thread safety and proper instance management.


37-60: Properties for connection_string, client, and collection are correctly implemented with both getters and setters, providing proper encapsulation.


61-62: The asynchronous close_connection method is correctly implemented for closing the MongoDB client connection.

lib/routes/motor.py (6)

29-29: The create_motor route is correctly implemented, using MotorController to handle the creation logic asynchronously.


40-47: The read_motor route is correctly implemented to fetch a motor by ID asynchronously using MotorController.


Line range hint 52-65: The update_motor route correctly handles the update operation by passing necessary parameters to MotorController and is implemented asynchronously.


69-76: The delete_motor route is correctly implemented to delete a motor by ID asynchronously using MotorController.


80-87: The read_rocketpy_motor route is correctly implemented to fetch a rocketpy representation of a motor by ID asynchronously.


91-98: The simulate_motor route is correctly implemented to simulate a motor by ID asynchronously using MotorController.

lib/routes/rocket.py (6)

32-32: The create_rocket route is correctly implemented, using RocketController to handle the creation logic asynchronously.


45-52: The read_rocket route is correctly implemented to fetch a rocket by ID asynchronously using RocketController.


Line range hint 57-73: The update_rocket route correctly handles the update operation by passing necessary parameters to RocketController and is implemented asynchronously.


77-84: The delete_rocket route is correctly implemented to delete a rocket by ID asynchronously using RocketController.


88-95: The read_rocketpy_rocket route is correctly implemented to fetch a rocketpy representation of a rocket by ID asynchronously.


99-106: The simulate_rocket route is correctly implemented to simulate a rocket by ID asynchronously using RocketController.

lib/repositories/environment.py (3)

19-21: The __init__ method in EnvRepository is correctly implemented, properly initializing the repository with the "environments" collection.


22-27: The fetch_env method is correctly implemented, effectively fetching an environment instance and setting the necessary properties.


30-38: Properties for env and env_id are correctly implemented with both getters and setters, providing proper encapsulation.

lib/routes/flight.py (8)

34-34: The create_flight route is correctly implemented, using FlightController to handle the creation logic asynchronously.


47-54: The read_flight route is correctly implemented to fetch a flight by ID asynchronously using FlightController.


58-65: The read_rocketpy_flight route is correctly implemented to fetch a rocketpy representation of a flight by ID asynchronously.


Line range hint 69-79: The update_flight_env route correctly handles the update operation by passing necessary parameters to FlightController and is implemented asynchronously.


Line range hint 84-98: The update_flight_rocket route correctly handles the update operation by passing necessary parameters to FlightController and is implemented asynchronously.


Line range hint 105-121: The update_flight route correctly handles the update operation by passing necessary parameters to FlightController and is implemented asynchronously.


125-132: The delete_flight route is correctly implemented to delete a flight by ID asynchronously using FlightController.


136-143: The simulate_flight route is correctly implemented to simulate a flight by ID asynchronously using FlightController.

lib/api.py (1)

11-11: The API configuration setup, including CORS settings and router inclusions, is correctly implemented for a public API.

lib/repositories/motor.py (3)

19-19: The constructor and CRUD methods correctly use the superclass constructor and handle exceptions using the parse_error function. Good use of structured logging.

Also applies to: 45-45, 71-71, 92-92


27-27: The use of class methods and property setters/getters is consistent and follows Pythonic best practices for encapsulation.

Also applies to: 43-43, 63-63, 90-90


2-2: Ensure that the parse_error function is correctly implemented and tested since it's heavily used for error handling in this module.

lib/repositories/rocket.py (3)

19-19: The constructor and CRUD methods correctly use the superclass constructor and handle exceptions using the parse_error function. Good use of structured logging.

Also applies to: 45-45, 75-75, 100-100


27-27: The use of class methods and property setters/getters is consistent and follows Pythonic best practices for encapsulation.

Also applies to: 43-43, 67-67, 98-98


2-2: Ensure that the parse_error function is correctly implemented and tested since it's heavily used for error handling in this module.

Verification successful

The parse_error function is defined in lib/__init__.py:

lib/__init__.py:def parse_error(error):

This confirms that the function is implemented and available for use in the module.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_) { $$$ }' lib/__init__.py

Length of output: 538



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_):\n    $$$' lib/__init__.py

Length of output: 85



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation across the entire repository. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_):\n    $$$'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the term `parse_error` across the entire repository to locate its definition or usage.
rg 'parse_error'

Length of output: 3104

lib/repositories/flight.py (3)

19-19: The constructor and CRUD methods correctly use the superclass constructor and handle exceptions using the parse_error function. Good use of structured logging.

Also applies to: 45-45, 75-75, 100-100


27-27: The use of class methods and property setters/getters is consistent and follows Pythonic best practices for encapsulation.

Also applies to: 43-43, 67-67, 98-98


2-2: Ensure that the parse_error function is correctly implemented and tested since it's heavily used for error handling in this module.

Verification successful

The parse_error function is correctly implemented in lib/__init__.py. It captures the exception type and formats the error message appropriately.

  • lib/__init__.py:
    def parse_error(error):
        exc_type = type(error).__name__
        exc_obj = f"{error}".replace("\n", " ").replace("   ", " ")
        return f"{exc_type} exception: {exc_obj}"
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_) { $$$ }' lib/__init__.py

Length of output: 538



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_):\n    $$$' 

Length of output: 69



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
rg 'def parse_error' --glob '*.py'

Length of output: 76



Script:

#!/bin/bash
# Description: Extract the implementation of `parse_error` function.

# Extract the function implementation from lib/__init__.py
sed -n '/def parse_error/,/^$/p' lib/__init__.py

Length of output: 221

lib/models/motor.py (3)

14-16: The renaming of enums and the addition of new properties follow the Python conventions for constants (uppercase) and are consistent across the module.

Also applies to: 20-21, 25-28, 32-32, 42-42


74-84: The use of the match statement for creating different tank types based on the tank_kind is a modern Python feature that enhances readability and maintainability.


131-131: The implementation of properties for motor_kind and motor_id is consistent and uses Python best practices for encapsulation and data hiding.

Also applies to: 135-142

lib/controllers/environment.py (3)

65-85: The methods for CRUD operations and simulation in EnvController are well-implemented with comprehensive error handling and logging. The use of HTTP exceptions for error states is appropriate for a web API.

Also applies to: 89-120, 163-192, 196-224, 228-268


47-47: The method get_rocketpy_env is a good example of a clean, single-responsibility function. It correctly transforms an Env model into a RocketPyEnvironment.


7-7: Ensure that the parse_error function is correctly implemented and tested since it's heavily used for error handling in this module.

lib/controllers/motor.py (4)

113-135: The methods for CRUD operations and simulation in MotorController are well-implemented with comprehensive error handling and logging. The use of HTTP exceptions for error states is appropriate for a web API.

Also applies to: 139-170, 213-244, 248-276, 279-343


34-34: The constructor and property methods in MotorController are well-defined, ensuring proper encapsulation and data integrity.

Also applies to: 51-51


Line range hint 52-104: The method get_rocketpy_motor effectively uses the match statement to instantiate the correct type of motor based on the motor_kind. This is a clean implementation of the factory pattern.


8-8: Ensure that the parse_error function is correctly implemented and tested since it's heavily used for error handling in this module.

Verification successful

The parse_error function is correctly implemented in lib/__init__.py and appears to handle error parsing by formatting the exception type and message. This implementation should be sufficient for its intended use in the motor.py module.

  • lib/__init__.py:
    def parse_error(error):
        exc_type = type(error).__name__
        exc_obj = f"{error}".replace("\n", " ").replace("   ", " ")
        return f"{exc_type} exception: {exc_obj}"
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation. Expect: Function definition and not just declaration.
ast-grep --lang python --pattern $'def parse_error($_, $_) { $$$ }' lib/__init__.py

Length of output: 538



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation in all Python files within the lib directory.
ast-grep --lang python --pattern 'def parse_error($_):' lib/**/*.py

Length of output: 670



Script:

#!/bin/bash
# Description: Verify the implementation of `parse_error` function.

# Test: Search for the function implementation across the entire repository.
rg 'def parse_error' --glob '*.py'

Length of output: 76



Script:

#!/bin/bash
# Description: Display the implementation of `parse_error` function.

# Test: Show the function implementation in lib/__init__.py.
sed -n '/def parse_error/,/^$/p' lib/__init__.py

Length of output: 221

lib/controllers/rocket.py (14)

18-18: Ensure consistent import of parse_error across all modules for uniform error handling.


38-38: Logger initialized correctly for debugging and error logging.


82-86: The method get_rocketpy_rocket is well-documented and follows good coding practices.


104-104: Good use of class methods to modularize the creation of rocket components.


135-135: Method create_rocket correctly handles exceptions and logs errors, aligning with the PR's focus on improved error handling.


161-161: Method get_rocket_by_id is well-structured with clear error handling and logging.


198-198: Method get_rocketpy_rocket_as_jsonpickle effectively combines data retrieval and conversion to JSON.


273-273: Method delete_rocket_by_id correctly handles exceptions and provides comprehensive logging.


304-304: Method simulate_rocket provides a detailed simulation of the rocket's flight, aligning with the PR's objectives.


480-480: Method get_rocketpy_nose is correctly implemented and documented.


520-520: Method get_rocketpy_tail is implemented correctly and follows good coding practices.


537-537: Method get_rocketpy_parachute correctly retrieves parachute data, ensuring accurate simulation.


557-557: Method check_parachute_trigger provides robust validation for parachute triggers.


99-99: Ensure that the motor is correctly retrieved and added to the rocket.

Verification successful

The motor is correctly retrieved and added to the rocket in lib/controllers/rocket.py using MotorController.get_rocketpy_motor(rocket.motor) within the rocketpy_rocket.add_motor method.

  • lib/controllers/rocket.py, line 99: MotorController.get_rocketpy_motor(rocket.motor) is used within the rocketpy_rocket.add_motor method, ensuring the motor is correctly retrieved and added to the rocket.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the motor is correctly retrieved and added to the rocket.

# Test: Search for the usage of `MotorController.get_rocketpy_motor`. Expect: Correct retrieval and addition of the motor.
rg --type python $'MotorController.get_rocketpy_motor' lib/controllers/rocket.py

Length of output: 110



Script:

#!/bin/bash
# Description: Verify that the motor is correctly retrieved and added to the rocket.

# Test: Search for the usage of `MotorController.get_rocketpy_motor`. Expect: Correct retrieval and addition of the motor.
rg 'MotorController.get_rocketpy_motor' --glob '*.py'

Length of output: 237



Script:

#!/bin/bash
# Description: Extract and review the relevant code snippets to ensure the motor is correctly retrieved and added to the rocket.

# Extract the relevant code snippets from `lib/controllers/rocket.py` and `lib/routes/motor.py`.
rg -A 5 -B 5 'MotorController.get_rocketpy_motor' lib/controllers/rocket.py lib/routes/motor.py

Length of output: 1310

lib/repositories/motor.py Outdated Show resolved Hide resolved
lib/repositories/rocket.py Outdated Show resolved Hide resolved
lib/controllers/rocket.py Outdated Show resolved Hide resolved
lib/models/flight.py Show resolved Hide resolved
lib/models/environment.py Show resolved Hide resolved
lib/controllers/rocket.py Show resolved Hide resolved
lib/repositories/repo.py Outdated Show resolved Hide resolved
lib/repositories/environment.py Outdated Show resolved Hide resolved
lib/controllers/rocket.py Show resolved Hide resolved
lib/repositories/flight.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

Outside diff range and nitpick comments (1)
lib/controllers/flight.py (1)

Line range hint 360-645: Method simulate_flight correctly simulates a flight and handles exceptions appropriately. Consider catching specific exceptions for more granular error management.

try:
    # Existing code...
except SpecificExceptionType as e:
    # Handle specific exceptions
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 803f0db and 7f50464.
Files selected for processing (11)
  • lib/controllers/flight.py (4 hunks)
  • lib/controllers/motor.py (6 hunks)
  • lib/controllers/rocket.py (6 hunks)
  • lib/repositories/environment.py (3 hunks)
  • lib/repositories/flight.py (1 hunks)
  • lib/repositories/motor.py (1 hunks)
  • lib/repositories/repo.py (1 hunks)
  • lib/repositories/rocket.py (1 hunks)
  • lib/routes/flight.py (4 hunks)
  • lib/routes/motor.py (2 hunks)
  • lib/routes/rocket.py (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • lib/controllers/motor.py
  • lib/repositories/environment.py
  • lib/repositories/flight.py
  • lib/repositories/rocket.py
  • lib/routes/flight.py
  • lib/routes/motor.py
  • lib/routes/rocket.py
Additional Context Used
Ruff (1)
lib/repositories/repo.py (1)

38-38: Undefined name logging

Additional comments not posted (12)
lib/repositories/repo.py (2)

15-20: Singleton pattern implementation looks good.

The use of a lock to ensure thread safety in the singleton pattern is correctly implemented.


23-41: Error handling in MongoDB client initialization is robust.

The use of a try-except block to handle and log initialization errors, and rethrowing a ConnectionError with a descriptive message, enhances the robustness of the database connection setup.

lib/repositories/motor.py (3)

45-69: Error handling and logging in create_motor are well-implemented.

The method uses parse_error to format exceptions and logs detailed error messages, which aligns with the PR's focus on enhancing error handling.


71-90: Retrieval and error handling in get_motor_by_id are correctly implemented.

The method correctly retrieves a motor by its ID and uses parse_error for exception formatting, which is consistent with the PR's objectives.


92-108: Deletion and error handling in delete_motor_by_id are well-implemented.

The method correctly deletes a motor by its ID and uses parse_error for exception formatting, enhancing the robustness of error handling.

lib/controllers/rocket.py (3)

176-209: Retrieval and error handling in get_rocket_by_id are correctly implemented.

The method correctly retrieves a rocket by its ID and uses parse_error for exception formatting, which is consistent with the PR's objectives.


Line range hint 319-492: Simulation and error handling in simulate_rocket are well-implemented.

The method correctly simulates a rocket and uses parse_error for exception formatting, enhancing the robustness of error handling.


150-172: Ensure proper error handling in create_rocket.

The create_rocket method includes detailed error handling and logging, which is crucial for diagnosing issues during rocket creation. Verify that these practices are consistent with other parts of the codebase.

Verification successful

The RocketController class contains multiple try and except blocks, indicating that error handling is implemented in various methods. This suggests that the error handling in the create_rocket method is consistent with the practices used throughout the class.

  • try and except Exception as e blocks are present, which handle general exceptions.
  • except HTTPException as e block is also present, indicating specific handling for HTTP-related exceptions.

These findings confirm that the error handling in the create_rocket method aligns with the overall error handling strategy in the RocketController class.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the error handling in `create_rocket` is robust and aligns with best practices.

# Test: Search for error handling practices in the RocketController class. Expect: Robust error handling.
rg --type python $'class RocketController' lib/controllers/rocket.py

Length of output: 100



Script:

#!/bin/bash
# Description: Verify that the error handling in `create_rocket` is robust and aligns with best practices.

# Test: Search for error handling practices in the RocketController class. Expect: Robust error handling.
rg --type py $'class RocketController' lib/controllers/rocket.py

Length of output: 89



Script:

#!/bin/bash
# Description: Verify error handling practices within the RocketController class.

# Test: Search for try and except blocks within the RocketController class.
rg --type py 'class RocketController' -A 50 lib/controllers/rocket.py | rg 'try|except'

Length of output: 89



Script:

#!/bin/bash
# Description: Verify error handling practices within the RocketController class.

# Test: Search for try and except blocks within the RocketController class.
rg --type py 'class RocketController' -A 200 lib/controllers/rocket.py | rg 'try|except'

Length of output: 257

lib/controllers/flight.py (4)

8-8: Import statements and logger setup are correctly implemented.

Also applies to: 35-35


59-66: Initialization of FlightController is correctly implemented.


67-82: Property methods for flight, rocket_option, and motor_kind are correctly implemented.


83-100: Method get_rocketpy_flight correctly constructs a RocketPyFlight object from a Flight object.

lib/repositories/repo.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
lib/repositories/motor.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
lib/controllers/flight.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between dc40720 and 7d615c7.
Files selected for processing (4)
  • lib/repositories/environment.py (3 hunks)
  • lib/repositories/flight.py (1 hunks)
  • lib/repositories/motor.py (1 hunks)
  • lib/repositories/rocket.py (1 hunks)
Files not reviewed due to errors (1)
  • lib/repositories/rocket.py (no review received)
Files skipped from review as they are similar to previous changes (2)
  • lib/repositories/environment.py
  • lib/repositories/motor.py
Additional comments not posted (2)
lib/repositories/flight.py (2)

24-27: LGTM! The fetch_flight method correctly updates the internal state based on the provided flight object.


48-49: LGTM! The find_flight method correctly retrieves flight data from the database.

lib/repositories/flight.py Show resolved Hide resolved
lib/repositories/flight.py Show resolved Hide resolved
lib/repositories/flight.py Show resolved Hide resolved
lib/repositories/flight.py Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Outside diff range and nitpick comments (2)
lib/controllers/flight.py (2)

35-36: Consider adding a brief comment explaining the purpose of the logger for future maintainability.


46-52: Ensure that the class docstring accurately reflects all methods available in the FlightController class. It seems some methods like simulate_flight are not mentioned.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7d615c7 and fc730e6.
Files selected for processing (5)
  • lib/controllers/environment.py (12 hunks)
  • lib/controllers/flight.py (4 hunks)
  • lib/controllers/motor.py (6 hunks)
  • lib/controllers/rocket.py (6 hunks)
  • lib/repositories/repo.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • lib/controllers/environment.py
  • lib/controllers/motor.py
Additional comments not posted (10)
lib/repositories/repo.py (3)

29-48: Excellent implementation of error handling in the _initialize_connection method.

This method correctly handles exceptions by logging the error and raising a ConnectionError, which is a robust approach for database connection failures.


53-57: Consider using asyncio.Lock() for thread safety in asynchronous environments.
[REFACTOR_SUGGESTion]

- async with self._lock:
+ async with asyncio.Lock():

This change ensures that the lock is properly handled in an asynchronous context, enhancing thread safety.


16-21: Ensure proper use of asynchronous singleton pattern.

lib/controllers/flight.py (7)

59-66: Initialization of FlightController with flight, rocket_option, and motor_kind is clear and well-defined. Good use of type hints for clarity.


167-204: The method get_rocketpy_flight_as_jsonpickle is correctly implemented to serialize a RocketPyFlight object. The error handling is robust, but as previously noted, consider catching more specific exceptions.


244-286: The update_env_by_flight_id method updates the environment of a flight. The implementation is correct, but the same issue with generic exception handling applies here.


289-333: The update_rocket_by_flight_id method updates the rocket information for a flight. The method is well-structured, but again, consider using more specific exceptions for better error management.


337-366: The delete_flight_by_id method is correctly implemented with appropriate error handling. The logging statements are helpful for debugging and auditing purposes.


Line range hint 369-653: The simulate_flight method is comprehensive and well-documented. It effectively simulates a flight and handles potential errors robustly. Consider adding more specific exception handling to enhance the error management.


131-165: The method get_flight_by_id is well-implemented with comprehensive error handling. However, ensure that the method flight_repo.get_flight_by_id actually sets the flight attribute, as it's used immediately after in the code.

Verification successful

The method flight_repo.get_flight_by_id correctly sets the flight attribute in the FlightRepository class.

  • Location: lib/repositories/flight.py
  • Code: self.flight = parsed_flight
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `flight_repo.get_flight_by_id` sets the `flight` attribute.
ast-grep --lang python --pattern $'class FlightRepository {
  $$$
  async get_flight_by_id($_) {
    $$$
  }
  $$$  
}'

Length of output: 626



Script:

#!/bin/bash
# Description: Verify that `flight_repo.get_flight_by_id` sets the `flight` attribute.
# First, locate the FlightRepository class definition
flight_repo_file=$(fd -e py 'FlightRepository' | xargs grep -l 'class FlightRepository')

# Then, check if the get_flight_by_id method sets the flight attribute
if [ -n "$flight_repo_file" ]; then
  grep -A 20 'async def get_flight_by_id' $flight_repo_file | grep 'self.flight'
else
  echo "FlightRepository class not found."
fi

Length of output: 183



Script:

#!/bin/bash
# Description: Verify that `flight_repo.get_flight_by_id` sets the `flight` attribute.
# First, locate the FlightRepository class definition more broadly
fd -e py 'FlightRepository' | xargs grep -l 'class FlightRepository'

# If found, check if the get_flight_by_id method sets the flight attribute
fd -e py | xargs grep -A 20 'async def get_flight_by_id' | grep 'self.flight'

Length of output: 213

lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/rocket.py Show resolved Hide resolved
lib/controllers/rocket.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fc730e6 and 05aa6fd.
Files selected for processing (1)
  • lib/repositories/repo.py (1 hunks)
Additional comments not posted (3)
lib/repositories/repo.py (3)

96-104: Add checks for initialization before setting the client.

The checks ensure that the repository is properly initialized before allowing access to the client, which prevents runtime errors due to uninitialized access.


108-116: Ensure properties are accessed only after initialization.

The defensive programming approach here is commendable. It ensures that the repository's properties are not accessed before the repository is fully initialized, thus avoiding potential runtime errors.


28-34: Ensure proper handling when the event loop is already running.

This code assumes that asyncio.run() can be called safely, which is not the case if the event loop is already running. This might raise an exception in such scenarios. Consider checking if the loop is running and handling it appropriately.

Verification successful

The current implementation in lib/repositories/repo.py correctly checks if the event loop is running and uses asyncio.run if it is not, otherwise it uses loop.create_task. This ensures proper handling of the event loop in different operational contexts.

  • The only instance of asyncio.run is in lib/repositories/repo.py, confirming that the event loop handling is consistent.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the event loop handling works correctly in all operational contexts.
# Test: Check for any reported issues or errors in logs when the event loop is already running.
rg --type python "loop.create_task"

Length of output: 66



Script:

#!/bin/bash
# Description: Verify that the event loop handling works correctly in all operational contexts.
# Test: Check for any reported issues or errors in logs when the event loop is already running.
rg --type py "loop.create_task"

Length of output: 128



Script:

#!/bin/bash
# Description: Verify the usage of asyncio.run and event loop handling across the codebase.
# Test: Check for any other instances of asyncio.run or similar event loop handling.
rg --type py "asyncio.run"

Length of output: 99

lib/repositories/repo.py Show resolved Hide resolved
lib/repositories/repo.py Outdated Show resolved Hide resolved
lib/repositories/repo.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 05aa6fd and 95a99fc.
Files selected for processing (2)
  • lib/controllers/environment.py (12 hunks)
  • lib/repositories/repo.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lib/controllers/environment.py
Additional Context Used
Learnings (1)
lib/repositories/repo.py (1)
User: GabrielBarberini
PR: RocketPy-Team/Infinity-API#20
File: lib/repositories/motor.py:19-27
Timestamp: 2024-05-22T21:46:36.377Z
Learning: The `Repositories` class is a singleton, which makes `MotorRepository` inherit this singleton behavior by transitivity.
Additional comments not posted (10)
lib/repositories/repo.py (10)

16-16: Consider using asyncio.Lock() instead of threading.Lock() for consistency with asyncio operations.


40-41: Improve error handling by specifying the type of exceptions to catch.


40-41: Refactor the connection initialization to handle specific MongoDB exceptions.


1-2: Ensure all necessary imports are included.


7-7: Proper logger initialization.


15-34: The singleton pattern is correctly implemented with thread safety using asyncio.Lock().


25-34: Asynchronous initialization logic is well-handled, ensuring the class is ready before use.


45-49: The asynchronous initialization method correctly sets up the connection and marks the instance as initialized.


86-117: Property methods for connection_string, client, and collection are well-implemented with checks for initialization.


118-121: The connection closing method is correctly implemented with appropriate logging.

lib/repositories/repo.py Outdated Show resolved Hide resolved
lib/repositories/repo.py Outdated Show resolved Hide resolved
@GabrielBarberini
Copy link
Collaborator Author

Walkthrough

The recent updates focus on refactoring repository and controller classes across various modules to enhance clarity, maintainability, and error handling. Key changes include renaming methods for consistency, adding logging and error handling, and updating method signatures to improve data management and operations. These modifications aim to streamline environment, flight, motor, and rocket operations, ensuring better code readability and maintainability.

Changes

File(s) Change Summary
lib/repositories/environment.py Refactored EnvRepository class methods and properties for better clarity and maintainability.
lib/repositories/flight.py Enhanced FlightRepository with logging, method renaming, and improved method signatures.
lib/repositories/motor.py Updated MotorRepository class with logging, method renaming, and property enhancements.
lib/repositories/rocket.py Refactored RocketRepository methods and properties for consistency and improved error handling.
lib/controllers/environment.py Updated method names and signatures in EnvironmentController for clarity and consistency.
lib/controllers/flight.py Enhanced FlightController with logging, method renaming, and improved error handling.
lib/controllers/motor.py Added logging, error handling, and method renaming in MotorController.
lib/controllers/rocket.py Refactored RocketController methods and properties for consistency and clarity.
lib/repositories/repo.py Introduced thread-safe singleton pattern and added connection management methods.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Controller
    participant Repository
    participant Database

    Controller->>Repository: fetch_env(env_id)
    activate Repository
    Repository->>Database: get_env_by_id(env_id)
    Database-->>Repository: Env data
    deactivate Repository
    Repository-->>Controller: Env data

    Controller->>Repository: create_env(env_data)
    activate Repository
    Repository->>Database: insert_env(env_data)
    Database-->>Repository: Insert result
    deactivate Repository
    Repository-->>Controller: Insert result
Loading

Poem

In code's vast garden, changes bloom,
Refactored paths dispel the gloom.
Logs now whisper, errors flee,
Repositories sing in harmony.
Controllers dance with newfound grace,
In this brightened, clearer space.
🚀✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

sequence diagram is wrong, there is no fetch by id, fetch is made with a BaseModel instance, e.g:

  • EnvRepository.fetch_env(Env())
  • FlightRepository.fetch_env(Flight())
  • MotorRepository.fetch_env(Motor())
  • RocketRepository.fetch_env(Rocket())

aasitvora99
aasitvora99 previously approved these changes May 29, 2024
Copy link

@aasitvora99 aasitvora99 left a comment

Choose a reason for hiding this comment

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

Fingers crossed

lib/__init__.py Outdated
return f"{exc_type} exception: {exc_obj}"


from .api import app # noqa
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for brining this line to the bottom of the file?

Suggested change
from .api import app # noqa
from .api import app # noqa

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To avoid circular imports. I use parse_error on api.py as well, and since importing app from it means the importing system will run over the whole file, it ended up breaking as parse_error was not ready yet.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 95a99fc and fea731f.
Files selected for processing (1)
  • lib/repositories/repo.py (1 hunks)
Additional Context Used
Learnings (1)
lib/repositories/repo.py (1)
User: GabrielBarberini
PR: RocketPy-Team/Infinity-API#20
File: lib/repositories/motor.py:19-27
Timestamp: 2024-05-22T21:46:36.377Z
Learning: The `Repositories` class is a singleton, which makes `MotorRepository` inherit this singleton behavior by transitivity.
Additional comments not posted (3)
lib/repositories/repo.py (3)

16-16: Use of asyncio.Lock() is appropriate for asynchronous operations.


80-85: Cleanup logic is implemented correctly.


86-116: Property methods are implemented correctly, ensuring proper checks for initialization.

lib/repositories/repo.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fea731f and 5b5fa81.
Files selected for processing (1)
  • lib/repositories/repo.py (1 hunks)
Additional Context Used
Learnings (1)
lib/repositories/repo.py (1)
User: GabrielBarberini
PR: RocketPy-Team/Infinity-API#20
File: lib/repositories/motor.py:19-27
Timestamp: 2024-05-22T21:46:36.377Z
Learning: The `Repositories` class is a singleton, which makes `MotorRepository` inherit this singleton behavior by transitivity.
Additional comments not posted (5)
lib/repositories/repo.py (5)

15-22: The implementation of the thread-safe singleton pattern using asyncio.Lock() is appropriate for async operations and correctly ensures that only one instance of the class is created per class type.


24-34: The asynchronous initialization logic using asyncio.Event() to manage the initialization state is well-implemented. The handling of different event loop states ensures that the initialization is correctly managed in both synchronous and asynchronous contexts.


80-85: The cleanup logic in the _cleanup_instance method is correctly implemented, ensuring that the MongoDB client is closed and the class instance is removed from the _instances dictionary.


86-110: The property methods for connection_string, client, and collection include checks for initialization, which is a good practice. This ensures that the properties are accessed only after the class is properly initialized.


72-78: Refine the exception handling in the _initialize_connection method to target specific MongoDB exceptions, which will improve the clarity and maintainability of the error handling code.

-        except Exception as e:
+        except pymongo.errors.ConnectionFailure as e:

Likely invalid or redundant comment.

lib/repositories/repo.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 11

Outside diff range and nitpick comments (2)
lib/controllers/flight.py (2)

4-4: Ensure imports are grouped and separated according to PEP 8 standards.

Imports from the same library (rocketpy.simulation.flight) should be grouped together to enhance readability and maintain PEP 8 compliance.


Line range hint 367-651: Optimize the simulate_flight method by handling specific simulation exceptions.

- except Exception as e:
+ except SimulationError as e:

Handling specific simulation-related exceptions will make the error handling more effective and the code easier to maintain.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b5fa81 and 9ac550b.

Files selected for processing (11)
  • lib/init.py (1 hunks)
  • lib/api.py (2 hunks)
  • lib/controllers/environment.py (13 hunks)
  • lib/controllers/flight.py (3 hunks)
  • lib/controllers/motor.py (5 hunks)
  • lib/controllers/rocket.py (6 hunks)
  • lib/repositories/environment.py (3 hunks)
  • lib/repositories/flight.py (1 hunks)
  • lib/repositories/motor.py (1 hunks)
  • lib/repositories/repo.py (1 hunks)
  • lib/repositories/rocket.py (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • lib/init.py
  • lib/api.py
  • lib/controllers/environment.py
  • lib/controllers/motor.py
  • lib/repositories/environment.py
  • lib/repositories/motor.py
  • lib/repositories/rocket.py
Additional context used
Learnings (1)
lib/repositories/repo.py (1)
User: GabrielBarberini
PR: RocketPy-Team/Infinity-API#20
File: lib/repositories/motor.py:19-27
Timestamp: 2024-05-22T21:46:36.377Z
Learning: The `Repositories` class is a singleton, which makes `MotorRepository` inherit this singleton behavior by transitivity.
Additional comments not posted (9)
lib/repositories/repo.py (2)

78-83: Ensure proper cleanup of MongoDB client connections.

The method _cleanup_instance properly handles the closing of MongoDB client connections and ensures that instances are removed from the class dictionary, which is crucial for preventing memory leaks.


22-33: Ensure proper handling of asynchronous initialization.

It's crucial to verify that all instantiations of the Repository class properly handle the asynchronous initialization to avoid race conditions or uninitialized state issues.

Verification successful

Ensure proper handling of asynchronous initialization.

The search results indicate that the Repository class and its subclasses are used within asynchronous contexts, such as async with EnvRepository() as env_repo. This suggests that the asynchronous initialization is being properly handled in these instances.

  • lib/controllers/environment.py
  • lib/controllers/rocket.py
  • lib/controllers/motor.py
  • lib/controllers/flight.py
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the asynchronous initialization is properly awaited in all usages of the Repository class.

# Test: Search for usages of Repository class instantiation. Expect: Proper handling of asynchronous initialization.
rg --type python 'Repository('

Length of output: 105



Script:

#!/bin/bash
# Description: Verify that the asynchronous initialization is properly awaited in all usages of the Repository class.

# Test: Search for usages of Repository class instantiation. Expect: Proper handling of asynchronous initialization.
rg --type python 'Repository\('

Length of output: 64



Script:

#!/bin/bash
# Description: Verify that the asynchronous initialization is properly awaited in all usages of the Repository class.

# Test: Search for usages of Repository class instantiation. Expect: Proper handling of asynchronous initialization.
rg 'Repository\('

Length of output: 1767

lib/repositories/flight.py (2)

17-25: Ensure proper initialization of flight properties.

The constructor and fetch_flight method properly initialize and set the flight and flight_id properties, which is crucial for ensuring that the repository is correctly prepared for operations.


53-81: Refine error handling by using more specific exceptions instead of a general Exception.

- except Exception as e:
+ except pymongo.errors.OperationFailure as e:
      exc_str = parse_error(e)
      logger.error(f"repositories.flight.create_flight: {exc_str}")
      raise Exception(f"Error creating flight: {exc_str}") from e

Using more specific exceptions helps in identifying the exact nature of the error and improves the maintainability of the code.

Likely invalid or redundant comment.

lib/controllers/rocket.py (1)

51-61: Ensure proper initialization of rocket properties.

The constructor properly initializes the rocket, rocket_option, and motor_kind properties, which is crucial for ensuring that the controller is correctly prepared for operations.

lib/controllers/flight.py (4)

8-8: Good addition of logging and error parsing utilities.

This aligns with the PR's objective to enhance logging and error handling capabilities.


57-63: Initialization of FlightController with dependency injection.

Using dependency injection for rocket_option and motor_kind enhances modularity and testability.


165-202: Method get_rocketpy_flight_as_jsonpickle correctly retrieves and serializes a RocketPyFlight object.

This method effectively uses exception handling and logging, aligning with the PR's objectives.


335-364: Good implementation of delete_flight_by_id with robust error handling.

This method correctly implements error handling and logging, which is crucial for operations that modify the database.

lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/flight.py Show resolved Hide resolved
lib/controllers/flight.py Show resolved Hide resolved
lib/repositories/repo.py Show resolved Hide resolved
lib/repositories/repo.py Show resolved Hide resolved
lib/repositories/flight.py Show resolved Hide resolved
lib/controllers/rocket.py Show resolved Hide resolved
lib/controllers/rocket.py Show resolved Hide resolved
@Gui-FernandesBR
Copy link
Member

Some tests from the Postman collection are not passing.

image

infinity-api  | 2024-05-31 01:13:20,373 - ERROR - <starlette.requests.Request object at 0x7fd42ccc3910>: RequestValidationError exception: [{'type': 'enum', 'loc': ('query', 'rocket_option'), 'msg': "Input should be 'CALISTO' or 'CUSTOM'", 'input': 'Calisto', 'ctx': {'expected': "'CALISTO' or 'CUSTOM'"}}, {'type': 'enum', 'loc': ('query', 'motor_kind'), 'msg': "Input should be 'HYBRID', 'SOLID' or 'LIQUID'", 'input': 'Hybrid', 'ctx': {'expected': "'HYBRID', 'SOLID' or 'LIQUID'"}}, {'type': 'enum', 'loc': ('body', 'rocket', 'motor', 'thrust_source'), 'msg': "Input should be 'CESARONI_M1670' or 'CUSTOM'", 'input': 'Cesaroni_M1670', 'ctx': {'expected': "'CESARONI_M1670' or 'CUSTOM'"}}, {'type': 'enum', 'loc': ('body', 'rocket', 'motor', 'tanks', 0, 'tank_kind'), 'msg': "Input should be 'LEVEL', 'MASS', 'MASSFlOW' or 'ULLAGE'", 'input': 'MassFlow', 'ctx': {'expected': "'LEVEL', 'MASS', 'MASSFlOW' or 'ULLAGE'"}}]

Comment on lines +603 to +604
global apogee
apogee = "apogee"
Copy link
Member

Choose a reason for hiding this comment

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

is this line really necessary? Seeting global variables in python like this is usually a code smeel

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Touché.

TLDR
Probably not necessary, it is a legacy code that needs to be refactored. Rocketpy interfaces within the API will be my next refactoring goal, this time I was focusing on the DB interfaces.

Context
When I looked at it this week I was also intrigued. So I'm not sure if this is a code duplication from the rocketpy original obj handling (I had to duplicate some of the rocketpy lib code to map the pydantic models into rocketpy native classes) or if it was a workaround for some other thing, It needs investigation and a refactoring for sure.

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

@GabrielBarberini overall it seems to be an amazing work. Nice refactoring.

It is complicated to review all the files in depth, specially bc I'm not too familiar with fastAPI yet.
However, I could understand most of the files and I can say that I'm ok with your changes.

@GabrielBarberini GabrielBarberini merged commit ca0eda6 into master May 31, 2024
2 of 3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 11, 2024
This was referenced Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants