Skip to content

Conversation

@kinshuksinghbist
Copy link
Contributor

@kinshuksinghbist kinshuksinghbist commented May 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of project parsing status by returning the current status after submitting a parsing task, instead of always showing a static "SUBMITTED" status.
    • Enhanced logic for deciding when to reparse projects, reducing unnecessary reparsing and improving reliability in error or stalled states.
  • Chores

    • Improved internal logging and removed unused code for better maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The logic for reparsing projects in the parsing controller was refined to consider more specific project states and timing. The code now checks if a project should be reparsed based on commit status, error state, or prolonged non-ready status. Status responses after parsing are now fetched dynamically from the database. Unused variables were removed, and time utilities were imported.

Changes

File(s) Change Summary
app/modules/parsing/graph_construction/parsing_controller.py Enhanced reparse logic with granular conditions, added time-based checks, improved status response, code cleanup, and imported datetime utilities.

Poem

In the warren of code, a check hops anew,
Projects now reparse when the timing is due.
With careful clocks ticking and statuses fetched,
The controller’s logic is finely etched.
🕰️🐇
No more stale carrots—just fresh, ready stew!

✨ 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.

@sonarqubecloud
Copy link

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: 0

🧹 Nitpick comments (1)
app/modules/parsing/graph_construction/parsing_controller.py (1)

294-302: Code duplication: Extract status fetching logic into a helper method.

The status fetching logic is duplicated between handling existing and new projects. Consider extracting this into a reusable helper method.

Extract the common logic into a helper method:

@staticmethod
async def get_current_project_status(
    project_manager: ProjectService, 
    project_id: str
) -> str:
    """Get the current status of a project from the database."""
    updated_project = await project_manager.get_project_from_db_by_id(project_id)
    return (
        updated_project["status"]
        if updated_project
        else ProjectStatusEnum.SUBMITTED.value
    )

Then replace both occurrences with:

-        updated_project = await project_manager.get_project_from_db_by_id(
-            project_id
-        )
-        current_status = (
-            updated_project["status"]
-            if updated_project
-            else ProjectStatusEnum.SUBMITTED.value
-        )
+        current_status = await ParsingController.get_current_project_status(
+            project_manager, project_id
+        )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3240fa5 and 780abf4.

📒 Files selected for processing (1)
  • app/modules/parsing/graph_construction/parsing_controller.py (6 hunks)
🔇 Additional comments (4)
app/modules/parsing/graph_construction/parsing_controller.py (4)

5-5: LGTM: Import addition is necessary for new functionality.

The added imports for datetime and timezone are required for the new time-based reparse logic implemented below.


221-229: Good improvement: Dynamic status fetching enhances accuracy.

Fetching the actual project status from the database instead of always returning SUBMITTED provides more accurate status information to clients. The fallback logic is well-implemented.


314-317: Consistent improvement: Dynamic status handling for new projects.

The change to fetch actual status instead of always returning SUBMITTED is consistent with the changes made for existing projects and improves accuracy.


162-202:

❓ Verification inconclusive

Potential timezone compatibility issue in datetime comparison.

The enhanced reparse logic is well-structured and addresses important use cases. However, there's a potential issue with timezone handling in the datetime comparison.

The comparison between current_time (timezone-aware) and project_updated_at could fail if the database field is stored as a naive datetime:

current_time = datetime.now(timezone.utc)  # timezone-aware
project_updated_at = project.updated_at    # potentially naive
time_diff = (current_time - project_updated_at).total_seconds() / 3600  # TypeError if timezone mismatch

Run this script to verify the timezone handling of the updated_at field:

If project.updated_at is naive, apply this fix:

-                        current_time = datetime.now(timezone.utc)
-                        project_updated_at = project.updated_at
+                        current_time = datetime.now(timezone.utc)
+                        project_updated_at = project.updated_at.replace(tzinfo=timezone.utc) if project.updated_at.tzinfo is None else project.updated_at

🏁 Script executed:

#!/bin/bash
# Description: Check how the updated_at field is defined in the Project model and verify timezone handling

# Search for the Project model definition
ast-grep --pattern 'class Project($$$) {
  $$$
  updated_at = $$$
  $$$
}'

# Search for any timezone-related configurations or datetime field definitions
rg -A 3 -B 3 "updated_at.*DateTime"

# Look for timezone configurations in the project
rg -i "timezone|utc" --type py

Length of output: 9250


🏁 Script executed:

#!/bin/bash
# Locate the Project model file and inspect its updated_at definition

# Find the file containing the Project model
project_file=$(rg -l --type py "class Project" | head -n 1)
echo "Project model file: $project_file"

# Show lines where updated_at is defined in that file
grep -n "updated_at" "$project_file"

Length of output: 172


🏁 Script executed:

#!/bin/bash
# Search for the Project model by __tablename__ and class name
rg -n "__tablename__.*projects" --type py
rg -n "class .*Project" --type py

Length of output: 79


Verify timezone-awareness of project.updated_at

I wasn’t able to locate the Project model definition—please confirm whether its updated_at column is stored as a timezone-aware timestamp. If it’s defined like

Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

(naive), you’ll get a TypeError when doing:

current_time = datetime.now(timezone.utc)     # tz-aware
project_updated_at = project.updated_at       # tz-naive
time_diff = (current_time - project_updated_at).total_seconds() / 3600

To guard against that, wrap the field in UTC if it’s naive:

 current_time = datetime.now(timezone.utc)
-project_updated_at = project.updated_at
+project_updated_at = (
+    project.updated_at.replace(tzinfo=timezone.utc)
+    if project.updated_at.tzinfo is None
+    else project.updated_at
+)
 time_diff = (current_time - project_updated_at).total_seconds() / 3600

Please verify your model’s updated_at and apply this fix if needed to avoid timezone mismatches.

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