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

Don't try to roll back the database on a failed message delivery, we … #2231

Merged
merged 6 commits into from
Feb 7, 2025

Conversation

danfunk
Copy link
Contributor

@danfunk danfunk commented Feb 6, 2025

…must allow the error so we have an audit of what happened. Otherwise we have to kill all trace of it, which just creates a grand mystery.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling in message processing to capture and record failure details clearly without reverting the process.
  • New Features

    • Introduced a new workflow process definition designed for error scenarios.
  • Tests

    • Added automated tests to verify that failure messages are properly handled and communicated during process execution errors.
    • New test method to validate error handling when starting a process expected to fail.
    • Updated test imports to include necessary components for new functionalities.

…must allow the error so we have an audit of what happened. Otherwise we have to kill all trace of it, which just creates a grand mystery.
Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Warning

Rate limit exceeded

@danfunk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 31e34b5 and 80a54fd.

📒 Files selected for processing (1)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/message_service.py (3 hunks)
📝 Walkthrough

Walkthrough

This pull request adjusts error handling in the MessageService by removing the automatic database rollback and instead marking related message instances as "failed" while preserving the failure reason. A comment is added to highlight a potential issue with deleting the message instance in the run_process_model_from_message method. Additionally, a new BPMN file is introduced that defines an executable process with message events and a script task, and a new unit test is added to verify that process start failures raise the expected error.

Changes

File(s) Change Summary
spiffworkflow-backend/src/spiffworkflow_backend/services/message_service.py Modified error handling in MessageService: removed rollback on exception; instead, update message_instance_send (and message_instance_receive, if present) status to "failed" while recording the failure cause; added comment regarding deletion of the message instance in error cases.
spiffworkflow-backend/tests/data/.../message-start-with-error.bpmn Added new BPMN file that defines an executable process named "MJE Process" (id: MJE_Process_test) with a start event triggering a message event, a script task containing a placeholder script, an end event, and definitions for two messages and a correlation key.
spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py Introduced a new test method, test_start_process_with_message_when_failure, which validates that starting a failing process raises a WorkflowExecutionServiceError with an appropriate error note; updated import statements to support the test functionality.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Test
    participant MS as MessageService
    participant DB as Database
    participant MIS as MessageInstance(s)
    participant Log as Logger

    U->>MS: Trigger message processing
    MS->>DB: Attempt to process message
    DB-->>MS: Exception/Error
    MS->>MIS: Set status to "failed" (send instance)
    alt If message_instance_receive exists
        MS->>MIS: Set status to "failed" (receive instance)
    end
    MS->>Log: Log error ("error after starting")
    MS->>DB: Delete message instance in run_process_model_from_message
Loading
sequenceDiagram
    participant C as Client
    participant BPMN as BPMN Engine
    participant SE as Start Event
    participant ST as Script Task
    participant EE as End Event

    C->>BPMN: Trigger "MJE_Process_test"
    BPMN->>SE: Initiate process via message event ("test_bad_process")
    SE->>ST: Flow to script task (contains placeholder script)
    ST->>EE: Complete process execution
Loading

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

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.

@danfunk danfunk requested review from jasquat and jbirddog February 6, 2025 19:53
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

🧹 Nitpick comments (1)
spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py (1)

100-140: LGTM! Test case effectively verifies error handling.

The test case correctly:

  1. Sets up a process that will fail
  2. Verifies that the error note is preserved

Consider these improvements:

  1. Remove unused payload variable
  2. Remove unused message_instance variable
  3. Break long line 126 into multiple lines for better readability
-        payload = {
-            "customer_id": "Sartography",
-            "po_number": 1001,
-            "description": "We built a new feature for messages!",
-            "amount": "100.00",
-        }

         # Load up the definition for the receiving process
         # It has a message start event that should cause it to fire when a unique message comes through
         # Fire up the first process
         load_test_spec(
             "test_group/message-start-with-error",
             process_model_source_directory="message-start-with-error",
             bpmn_file_name="message-start-with-error.bpmn",
         )

         # Now send in the message
         user = self.find_or_create_user()
-        message_triggerable_process_model = MessageTriggerableProcessModel.query.filter_by(message_name="test_bad_process").first()
+        message_triggerable_process_model = (
+            MessageTriggerableProcessModel.query
+            .filter_by(message_name="test_bad_process")
+            .first()
+        )
         assert message_triggerable_process_model is not None

-        message_instance = MessageInstanceModel(
-            message_type="send",
-            name="test_bad_process",
-            payload={},
-            user_id=user.id,
-        )
         g.user = user
🧰 Tools
🪛 Ruff (0.8.2)

108-108: Local variable payload is assigned to but never used

Remove assignment to unused variable payload

(F841)


126-126: Line too long (131 > 130)

(E501)


129-129: Local variable message_instance is assigned to but never used

Remove assignment to unused variable message_instance

(F841)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8644dca and f52c6ac.

📒 Files selected for processing (3)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/message_service.py (3 hunks)
  • spiffworkflow-backend/tests/data/message-start-with-error/message-start-with-error.bpmn (1 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py (3 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_message_service.py

108-108: Local variable payload is assigned to but never used

Remove assignment to unused variable payload

(F841)


126-126: Line too long (131 > 130)

(E501)


129-129: Local variable message_instance is assigned to but never used

Remove assignment to unused variable message_instance

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: typeguard 3.12 / ubuntu-latest sqlite
  • GitHub Check: typeguard 3.11 / ubuntu-latest sqlite
  • GitHub Check: tests 3.11 / macos-latest sqlite
  • GitHub Check: tests 3.10 / ubuntu-latest sqlite
  • GitHub Check: tests 3.12 / ubuntu-latest sqlite
  • GitHub Check: tests 3.11 / ubuntu-latest sqlite
  • GitHub Check: tests 3.12 / ubuntu-latest postgres
  • GitHub Check: tests 3.11 / ubuntu-latest postgres
  • GitHub Check: tests 3.12 / ubuntu-latest mysql
  • GitHub Check: tests 3.11 / ubuntu-latest mysql
  • GitHub Check: check_docker_start_script
  • GitHub Check: build
  • GitHub Check: pixeebot[bot]
🔇 Additional comments (2)
spiffworkflow-backend/tests/data/message-start-with-error/message-start-with-error.bpmn (1)

1-45: LGTM! Test file is well-structured for error handling verification.

The BPMN file is correctly configured with:

  • An executable process with a message start event
  • A script task with invalid code to trigger a failure
  • Proper sequence flows and message definitions
spiffworkflow-backend/src/spiffworkflow_backend/services/message_service.py (1)

151-164: LGTM! Improved error handling by preserving error information.

The changes correctly implement the PR's objective by:

  1. Preventing database rollback to preserve error information
  2. Setting message instance statuses to "failed"
  3. Recording failure causes
  4. Adding a descriptive error note

Copy link
Contributor

@burnettk burnettk left a comment

Choose a reason for hiding this comment

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

awesome

@burnettk burnettk merged commit bbbc157 into main Feb 7, 2025
24 checks passed
@burnettk burnettk deleted the bug/message_start_error branch February 7, 2025 18:54
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