Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

muhammad-ali-e
Copy link
Contributor

@muhammad-ali-e muhammad-ali-e commented Apr 21, 2025

What

  • Fixed HTTP status code mapping for workflow execution status checks in the API deployment views
  • Changed PENDING and EXECUTING states to return 200 OK instead of 422 Unprocessable Entity
  • Enhanced code structure with better documentation and separated data filtering logic
  • Added comprehensive method documentation explaining status code mappings

Why

  • API clients were receiving incorrect 422 status codes for valid in-progress states (PENDING/EXECUTING)
  • This caused integration issues where clients expected 200 OK for successful status checks per API documentation
  • Current behavior was inconsistent with documented API contract
  • Users reported integration failures due to unexpected status codes

How

  • Modified backend/api_v2/api_deployment_views.py to return proper HTTP status codes:
    • PENDING, EXECUTING200 OK (was 422 before)
    • COMPLETED200 OK (no change)
    • ERROR, STOPPED422 Unprocessable Entity (no change)
    • Result already acknowledged406 Not Acceptable (no change)
  • Refactored the get method with improved structure and documentation
  • Extracted data filtering logic into separate _filter_response_data method
  • Added comprehensive docstring explaining status code mappings

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No, this change fixes broken behavior and aligns with documented API contract
  • Clients expecting 200 OK for PENDING/EXECUTING states will now work correctly
  • Any clients incorrectly relying on 422 for in-progress states were already broken per documentation
  • Status response body format remains unchanged, only HTTP status codes are corrected
  • This restores expected behavior rather than introducing new behavior

Database Migrations

  • None required

Env Config

  • None required

Relevant Docs

  • Fixes discrepancy with Unstract API documentation which specifies 200 OK for valid execution states
  • Related to UN-2309 Jira ticket for avoiding 422 response for in-progress states

Related Issues or PRs

  • Addresses UN-2309: Avoid 422 response for in-progress workflow execution states
  • Fixes reported integration issues with workflow execution status API calls

Dependencies Versions

  • None required

Notes on Testing

  • Manual testing recommended with workflow execution status API endpoints
  • Verify PENDING and EXECUTING states return 200 OK instead of 422
  • Confirm ERROR/STOPPED states still return 422 as expected
  • Test client integration scenarios that were previously failing

Screenshots

N/A - Backend API change

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Copy link

Copy link
Contributor

@chandrasekharan-zipstack chandrasekharan-zipstack left a comment

Choose a reason for hiding this comment

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

Changes LGTM - however

  1. Won't this break existing clients that rely on the existing (flawed) logic? Ideally we should version the API deployments to aid with such changes however since we don't have it in place I'm wondering how we can carry this out cleanly
  2. We might have to update accordingly in our python-client and the API deployments batch run script if required

@muhammad-ali-e muhammad-ali-e changed the title update status codes update status codes (Hold- to discuss the existing client) May 15, 2025
@muhammad-ali-e muhammad-ali-e changed the title update status codes (Hold- to discuss the existing client) update status codes (Hold- to discuss about backward compatibility) May 15, 2025
Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of execution status responses, ensuring accurate HTTP status codes and clearer messages for different execution states.
  • Refactor

    • Enhanced response data filtering for deployment executions, providing more modular and maintainable logic.
    • Clarified and documented the behavior of the deployment execution status endpoint for end-users.
## Summary by CodeRabbit

* **Bug Fixes**
  * Improved handling of deployment execution statuses with clearer and more accurate HTTP responses for acknowledged, completed, executing, pending, and error states.

* **Refactor**
  * Clarified and streamlined the logic for determining response statuses based on execution state.

## Walkthrough

The control flow in the `get` method of the `DeploymentExecution` API view was refactored to more explicitly handle various execution statuses. The response status codes and messages were adjusted based on the execution state, with clearer branching and an early return for acknowledged results. Enum usage was updated for status checks. A new helper method was added to modularize response data filtering based on request flags and global settings.

## Changes

| File(s)                        | Change Summary                                                                                                           |
|-------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| backend/api_v2/api_deployment_views.py | Refactored `get` method to restructure response status logic, added early return for acknowledged results, replaced enum import, and introduced `_filter_response_data` helper method for conditional response data filtering. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Client
    participant API_View
    participant ExecutionStatus

    Client->>API_View: GET /deployment-execution
    API_View->>ExecutionStatus: Check execution status
    alt Result already acknowledged
        API_View-->>Client: HTTP 406 (Not Acceptable) with message
    else Execution completed
        API_View-->>Client: HTTP 200 with result (filtered as needed)
    else Executing or Pending
        API_View-->>Client: HTTP 200 with current status (filtered as needed)
    else Other statuses (stopped, error, etc.)
        API_View-->>Client: HTTP 422 (Unprocessable Entity) with error info
    end

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**
**Cache: Disabled due to Reviews > Disable Cache setting**
**Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between ee0b9c03b974722be1157607725d89de51d501a9 and 3712957f348350a8138e9ab8fc3548cbc0b48f3d.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `backend/api_v2/api_deployment_views.py` (3 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* backend/api_v2/api_deployment_views.py

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)</summary>

* GitHub Check: build

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcSHFcLzpIACIAVQA5MAAmAFYADgAWSABtADEASQANAF1IAGF8Cn8xKIAJaGgre1xqbGQmJWQAM0rIAHdKgGsur3w+yBIAD1E8eHwsRBbcNsgAQSt86Mg5SDbKSGZsWDQnWjA0L3gwEkgACltIMwBGVIA2AEp0Wlp/RERpFAYJhVUSheqNZqtdqKG7MNDcbjwDBEZBIsKwG4DCjDUbjKYzcTzSHLZDrfL9dQILC4DGQABa8G4izQDEGAHpsBhFlQxH4SNx8Ih1JVZBojABpEjybDcWjUAFIhhebBKDhGKC5eCTJFEd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JYXdpVxZvQHEoUjGDSUpI2sg+5fBPDKSxewdQ4ZEBaVPPByJn0MCtCFTKAFdAuBxiUP2Eytx/heC6PK7tIQuAMSCCEMuFAiBORU2wLg3JnUeTsyQBz2U4ZeVGT5Jy1q1qeQIFwYZAYvPjIqWtFMSFPgMO0lW/4HYsCkb+PGILniQyDrIfF6ytknGORcm5XLnmxkhm8QFIK2Zbjf12ds4quyVz7ORMZ2K8UW6QF/UW+glWrWMqTQNES7wDBQAU/0zrWmdOQDA+1KjvUWj6fSUZxW0GuDpdTgxKDIa4aKmVEoJy+aw1cHtvgLwG2gRbZ6iWqqUZtj4EO1FvQUl5j5Ksol5AQyRlFdwMtqZVk4wOMGHZNxriCtve87M0re4DABOiPQxhzCJjs1iRwwg6ieFaNYDovwaB9GOGifIHY0UzHSMsXI2HfD1BOXgLQRAQbQd0CcsyCgoQ5G2JYSQBsAhoEMAbBA9nAB2DIPO5x/SeE8FIPPXgNh5wLlItA0jQKUCkJ4tAUgNieGgWBxOFGQAgTzl40DRddAgRkNIEDldoDSE8CBaQSDQJUGkLoDATdG4YAITnAgjcG/oEzknA8ycU6p0OfytPWH6CAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Zipstack/unstract&utm_content=1256):

- 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](https://www.coderabbit.ai/contact-us/support) 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](https://docs.coderabbit.ai/finishing-touches/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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@muhammad-ali-e muhammad-ali-e changed the title update status codes (Hold- to discuss about backward compatibility) UN-2584 [FIX] Corrected HTTP status codes for workflow execution status API Jul 12, 2025
muhammad-ali-e and others added 2 commits July 12, 2025 11:08
…us API

Fixed PENDING and EXECUTING states to return 200 OK instead of 422,
resolving API integration issues where clients expected 200 OK for
valid in-progress states per documentation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

filepath function $$\textcolor{#23d18b}{\tt{passed}}$$ SUBTOTAL
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_logs}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup\_skip}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_client\_init}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_exists}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config\_without\_mount}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_run\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_for\_sidecar}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_sidecar\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{TOTAL}}$$ $$\textcolor{#23d18b}{\tt{11}}$$ $$\textcolor{#23d18b}{\tt{11}}$$

Copy link

@muhammad-ali-e muhammad-ali-e marked this pull request as draft July 17, 2025 11:59
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