Skip to content

Bandit fixes#564

Merged
chrisaddy merged 6 commits intomasterfrom
bandit-fixes
Jun 3, 2025
Merged

Bandit fixes#564
chrisaddy merged 6 commits intomasterfrom
bandit-fixes

Conversation

@chrisaddy
Copy link
Copy Markdown
Collaborator

@chrisaddy chrisaddy commented May 28, 2025

This pull request introduces several changes to improve request handling, enhance code quality, and update linting configurations. The most significant changes include adding timeouts to HTTP requests, modifying code annotations for better clarity, and refining linting rules for improved code consistency and security.

Request Handling Improvements:

  • Added a timeout=30 parameter to all HTTP requests (POST, GET, and DELETE) in equity_bars_steps.py and health_steps.py to prevent indefinite waiting during network calls. [1] [2] [3] [4]

Code Quality Enhancements:

  • Updated the SQL query string in bars_query with a # noqa: S608 comment to suppress a security warning related to SQL string formatting.
  • Removed the response_model parameter from the fetch_equity_bars endpoint in main.py to simplify the FastAPI route definition.

Linting Configuration Updates:

  • Refactored pyproject.toml to rename [tool.ruff] to [tool.ruff.lint] and added new linting rule categories (ASYNC, FAST, S, YTT) for enhanced code checks.
  • Introduced per-file-ignores in the pyproject.toml to suppress specific security warnings (S101) in test and step definition files.

Summary by CodeRabbit

  • Bug Fixes

    • Added a 30-second timeout to all relevant HTTP requests to prevent indefinite waiting for server responses.
  • Chores

    • Updated code comments and formatting for improved code quality and security linting.
    • Enhanced linting configuration to include additional rule checks and specific file-based exceptions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2025

Walkthrough

A 30-second timeout was added to all HTTP requests in several step implementation files. The SQL query in the main application was updated with a lint suppression comment, and the FastAPI route decorator was simplified by removing the explicit response model. Ruff linter configuration was expanded and refactored in the project settings.

Changes

File(s) Change Summary
application/datamanager/features/steps/equity_bars_steps.py,
application/datamanager/features/steps/health_steps.py
Added a 30-second timeout parameter to all HTTP requests using the requests library.
application/datamanager/src/datamanager/main.py Added lint suppression comment to SQL string and removed explicit response model from FastAPI route decorator.
pyproject.toml Renamed Ruff config section, expanded rule codes, and added per-file ignore rules for security checks.

Suggested labels

python, bug

Poem

In the garden of code where requests now wait,
Thirty seconds they pause—no longer their fate!
Lint rules expanded, security in view,
SQL strings tidied, decorators anew.
Ruff barks with new wisdom, the project feels snug—
A rabbit’s delight, with a hop and a hug! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented May 28, 2025

Graphite Automations

"Assign author to pull request" took an action on this PR • (05/28/25)

1 assignee was added to this PR based on John Forstmeier's automation.

forstmeier
forstmeier previously approved these changes May 28, 2025
Base automatically changed from add-annotations to master May 28, 2025 21:21
@chrisaddy chrisaddy dismissed forstmeier’s stale review May 28, 2025 21:21

The base branch was changed.

@forstmeier forstmeier added this to the Rebuild milestone May 31, 2025
Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (1)
application/datamanager/src/datamanager/main.py (1)

24-24: Fix trailing whitespace.

There's unnecessary trailing whitespace after the opening triple quotes. This should be removed for clean code formatting.

-    return f""" 
+    return f"""
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 24-24: Trailing whitespace

(C0303)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6bf51c and 353d08e.

📒 Files selected for processing (4)
  • application/datamanager/features/steps/equity_bars_steps.py (3 hunks)
  • application/datamanager/features/steps/health_steps.py (1 hunks)
  • application/datamanager/src/datamanager/main.py (3 hunks)
  • pyproject.toml (1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
application/datamanager/src/datamanager/main.py

[convention] 24-24: Trailing whitespace

(C0303)

🔇 Additional comments (9)
application/datamanager/features/steps/health_steps.py (1)

10-10: Excellent security improvement!

Adding a 30-second timeout to the HTTP request prevents indefinite blocking and improves the robustness of the health check step. This is a best practice for all HTTP requests in production code.

application/datamanager/src/datamanager/main.py (2)

38-38: Appropriate security warning suppression.

The # noqa: S608 comment correctly suppresses the Bandit security warning for SQL string formatting. This is appropriate when the developer has verified that the f-string usage is safe (in this case, the variables are date objects, not user input).


114-114: Verify impact of removing explicit response model.

The removal of response_model=BarsSummary from the FastAPI route decorator will affect the automatically generated OpenAPI documentation. The endpoint will still return the correct type due to the function signature, but the API docs may be less explicit.

Ensure this change aligns with your API documentation requirements. If explicit API documentation is important, consider keeping the response_model parameter.

application/datamanager/features/steps/equity_bars_steps.py (3)

27-27: Excellent timeout addition for POST requests.

Adding a 30-second timeout to the POST request improves reliability and prevents indefinite blocking during network issues.


37-37: Good timeout addition for GET requests.

The 30-second timeout on GET requests maintains consistency with other HTTP operations and improves robustness.


52-52: Consistent timeout implementation for DELETE requests.

Adding the timeout parameter to DELETE requests completes the comprehensive timeout implementation across all HTTP methods in this file.

pyproject.toml (3)

68-68: Updated ruff configuration structure.

The section rename from [tool.ruff] to [tool.ruff.lint] aligns with the current ruff configuration format and best practices.


70-76: Enhanced linting coverage with security rules.

Excellent expansion of linting rules! The addition of security checks ("S" - Bandit), FastAPI-specific rules ("FAST"), async rules ("ASYNC"), and other categories will significantly improve code quality and security detection across the codebase.


77-79: Appropriate per-file ignores for test files.

The per-file ignores for "S101" (assert statement security warnings) in test and feature step directories is appropriate, as assert statements are expected and necessary in test code. This prevents false positives while maintaining security checks in production code.

@chrisaddy chrisaddy merged commit 67bb8c6 into master Jun 3, 2025
2 of 3 checks passed
@chrisaddy chrisaddy deleted the bandit-fixes branch June 3, 2025 01:42
@coderabbitai coderabbitai Bot mentioned this pull request Jun 4, 2025
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.

2 participants