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

[14.0][FIX] cetmix_tower_server_notify_backend On delete flight plan issue #197

Conversation

ivs-cetmix
Copy link
Contributor

@ivs-cetmix ivs-cetmix commented Jan 30, 2025

When a Server is deleted an on delete Flight Plan is triggered. As soon as this Flight Plan finishes with success, the Server is deleted too. All related records are deleted with it.

This creates an issue when notification is sent for a log record that is already deleted.

This commit fixes this issue by checking if the record exists before sending a notification.

Task: 4320

Summary by CodeRabbit

  • Bug Fixes

    • Improved notification logic for command completion to handle edge cases.
    • Enhanced record validation before sending notifications.
    • Refined status checking mechanism to prevent potential notification errors.
    • Added a new error message for scenarios where a server is deleted with an "On Delete Plan" set.
  • Documentation

    • Updated URLs and added a "Changelog" section in the README.
    • Simplified documentation content regarding module functionality and dependencies.
    • Reorganized HTML documentation structure and updated links.

Copy link

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request modifies the _command_finished method in the CxTowerCommandLog class within the cx_tower_command_log.py file. The changes enhance the conditional logic for handling command completion notifications by adding a check for record existence before processing notifications. This adjustment specifically addresses scenarios where a Flight Plan is executed during server deletion, ensuring that notifications are only sent for valid records and statuses. Additionally, updates were made to documentation files to reflect changes in URLs and to enhance clarity regarding module functionality.

Changes

File Change Summary
cetmix_tower_server_notify_backend/models/cx_tower_command_log.py Updated _command_finished method with improved conditional logic for record existence and notification processing.
cetmix_tower_server_notify_backend/README.rst Updated URLs for the GitHub repository and added a changelog section. Removed dependency information.
cetmix_tower_server_notify_backend/readme/.newsfragments/4320.bugfix Added error message for server deletion with an "On Delete Plan" set.
cetmix_tower_server_notify_backend/readme/DESCRIPTION.md Removed specific details on functionality and dependencies; replaced with general statements.
cetmix_tower_server_notify_backend/static/description/index.html Simplified content, added changelog section, updated links, and reorganized table of contents.

Possibly related PRs

  • [14.0][IMP] cetmix_tower_server: UI/UX imporovents #134: The changes in the CxTowerCommandLog model, specifically the addition of the command_action field, relate to the modifications in the _command_finished method in the CxTowerCommandLog class, as both involve handling command actions and statuses.
  • [14.0][IMP] cetmix_tower_server: On delete flight plan #189: The enhancements to the CxTowerPlanLog class, particularly the new _plan_finished() method and the modifications to the finish() method, are related to the changes in the _command_finished method, as both involve managing the completion and status of operations related to flight plans and server deletions.

Suggested reviewers

  • Aldeigja

🪧 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.
    • 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 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 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 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. (Beta)
  • @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.

Copy link

@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 (2)
cetmix_tower_server_notify_backend/models/cx_tower_command_log.py (2)

17-19: LGTM! Clear explanation of the edge case.

The comments effectively explain the race condition where records might be deleted during Flight Plan execution on server deletion. The exists() check is the correct approach to handle this scenario.

Consider adding a proper type annotation for the exists() method instead of using # type: ignore. You can use:

from typing import cast
# ...
if not cast(bool, rec.exists()) or not rec.plan_log_id:

Line range hint 21-40: Consider caching required values before notifications.

While the existence check prevents initial errors, the record could still be deleted between the check and notification calls. Consider storing required values before sending notifications.

 if not rec.exists() or not rec.plan_log_id:  # type: ignore
     continue
+
+# Cache required values to prevent potential errors if record is deleted
+command_name = rec.command_id.name
+server_name = rec.server_id.name
+
 if rec.command_status == 0:
     rec.create_uid.notify_success(
         message=_(
             "%(timestamp)s<br/>" "Command '%(name)s' finished successfully",
-            name=rec.command_id.name,
+            name=command_name,
             timestamp=context_timestamp,
         ),
-        title=rec.server_id.name,
+        title=server_name,
         sticky=True,
     )
 else:
     rec.create_uid.notify_danger(
         message=_(
             "%(timestamp)s<br/>"
             "Command '%(name)s'"
             " finished with error. "
             "Please check the command log for details.",
-            name=rec.command_id.name,
+            name=command_name,
             timestamp=context_timestamp,
         ),
-        title=rec.server_id.name,
+        title=server_name,
         sticky=True,
     )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92a82c8 and a058f45.

📒 Files selected for processing (1)
  • cetmix_tower_server_notify_backend/models/cx_tower_command_log.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test with OCB

@ivs-cetmix ivs-cetmix force-pushed the 14.0-t4320-cetmix_tower_server_notify_backend-fix_on_delete branch from a058f45 to e1fe3a5 Compare January 30, 2025 22:29
@ivs-cetmix ivs-cetmix changed the title [14.0][FIX] cetmix_tower_server_notify_backend On delete [14.0][FIX] cetmix_tower_server_notify_backend On delete flight plan issue Jan 30, 2025
When a Server is deleted an on delete Flight Plan is triggered.
As soon as this Flight Plan finishes with success,
the Server is deleted too. All related records are deleted with it.

This creates an issue when notification is sent for a log record
that is already deleted.

This commit fixes this issue by checking if the record exists
before sending a notification.

Task: 4320
@ivs-cetmix ivs-cetmix force-pushed the 14.0-t4320-cetmix_tower_server_notify_backend-fix_on_delete branch from e1fe3a5 to f601a58 Compare January 31, 2025 14:09
Copy link

@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 (3)
cetmix_tower_server_notify_backend/readme/.newsfragments/4320.bugfix (1)

1-1: Enhance the news fragment with more details about the fix.

While the error message is clear, consider expanding it to include information about the implemented fix. This helps users understand both the issue and its resolution.

-Error when deleting a Server with an "On Delete Plan" set.
+Fixed an issue where notifications were being sent for deleted records when deleting a Server with an "On Delete Plan" set. The system now verifies record existence before sending notifications.
cetmix_tower_server_notify_backend/static/description/index.html (1)

381-385: Consider adding changelog entries.

The new "Changelog" section has been added but appears to be empty. Consider documenting the changes made in this PR, particularly the fix for the server deletion notification issue.

Also applies to: 398-400

cetmix_tower_server_notify_backend/readme/DESCRIPTION.md (1)

1-3: Fix bare URL in documentation.

The documentation link should be formatted as a proper Markdown link to comply with markdownlint guidelines.

Apply this diff to fix the bare URL:

-Please check the official documentation for more information: https://cetmix.com/tower
+Please check the official documentation for more information: [https://cetmix.com/tower](https://cetmix.com/tower)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

3-3: Bare URL used
null

(MD034, no-bare-urls)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1fe3a5 and f601a58.

📒 Files selected for processing (5)
  • cetmix_tower_server_notify_backend/README.rst (3 hunks)
  • cetmix_tower_server_notify_backend/models/cx_tower_command_log.py (1 hunks)
  • cetmix_tower_server_notify_backend/readme/.newsfragments/4320.bugfix (1 hunks)
  • cetmix_tower_server_notify_backend/readme/DESCRIPTION.md (1 hunks)
  • cetmix_tower_server_notify_backend/static/description/index.html (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cetmix_tower_server_notify_backend/README.rst
🚧 Files skipped from review as they are similar to previous changes (1)
  • cetmix_tower_server_notify_backend/models/cx_tower_command_log.py
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
cetmix_tower_server_notify_backend/readme/DESCRIPTION.md

3-3: Bare URL used
null

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test with OCB
🔇 Additional comments (2)
cetmix_tower_server_notify_backend/static/description/index.html (2)

372-375: LGTM! Documentation updates align with the PR objectives.

The simplified module description and documentation link provide clearer guidance for users.


402-406: LGTM! Updated links and contribution note.

The bug tracker links and credits section have been properly updated to reflect version 14.0.

Also applies to: 410-419

@ivs-cetmix
Copy link
Contributor Author

/ocabot merge patch

@CetmixGitDrone
Copy link

On my way to merge this fine PR!
Prepared branch 14.0-dev-ocabot-merge-pr-197-by-ivs-cetmix-bump-patch, awaiting test results.

@CetmixGitDrone CetmixGitDrone merged commit 8dec123 into 14.0-dev Jan 31, 2025
8 checks passed
@CetmixGitDrone
Copy link

Congratulations, your PR was merged at 4e8191b. Thanks a lot for contributing to cetmix. ❤️

@CetmixGitDrone CetmixGitDrone deleted the 14.0-t4320-cetmix_tower_server_notify_backend-fix_on_delete branch January 31, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants