Skip to content

Resolve clip tool ordering in subscription requests #1207

Open
asonnenschein wants to merge 6 commits intomainfrom
adrian/clip-to-source-error
Open

Resolve clip tool ordering in subscription requests #1207
asonnenschein wants to merge 6 commits intomainfrom
adrian/clip-to-source-error

Conversation

@asonnenschein
Copy link
Contributor

Resolve clip tool ordering in subscription requests

GH issue #1206

Problem

When using clip_to_source=True in build_request(), the clip tool was appended to the end of the tool list, resulting in incorrect processing order. See the documentation on creating toolchains for more information about toolchain processing order.

Solution

  • Defined tool processing weights in planet/constants.py as _SUBSCRIPTION_TOOL_WEIGHT
  • Added _validate_tool_order() to validate input tool lists are in correct order
  • Added _insert_clip_tool() to insert clip at the correct position based on tool weights
  • Updated build_request() to use these helper methods

Example

Before:

tools = [{"type": "harmonize"}, {"type": "file_format"}]
build_request(..., tools=tools, clip_to_source=True)
# Result: ["harmonize", "file_format", "clip"]  ❌

After:

tools = [{"type": "harmonize"}, {"type": "file_format"}]
build_request(..., tools=tools, clip_to_source=True)
# Result: ["harmonize", "clip", "file_format"]  ✅

Testing

  • Added 17 new parametrized tests covering tool ordering validation and clip insertion
  • All 66 tests pass
  • Coverage for planet/subscription_request.py increased to 86%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR resolves an issue where the clip tool was incorrectly placed at the end of the tool list when using clip_to_source=True in subscription requests, causing API validation errors due to incorrect tool sequencing.

Changes:

  • Introduced tool processing weights to define correct ordering constraints for subscription tools
  • Added validation to ensure user-provided tools are in correct order before processing
  • Implemented smart insertion logic to place the clip tool at the appropriate position based on tool weights

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
planet/constants.py Defines _SUBSCRIPTION_TOOL_WEIGHT dictionary mapping tool names to processing order weights (1-4)
planet/subscription_request.py Adds _validate_tool_order() and _insert_clip_tool() helper functions; updates build_request() to validate and correctly insert clip tool
tests/unit/test_subscription_request.py Adds 17 comprehensive parametrized tests covering tool order validation and clip insertion scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

asonnenschein and others added 2 commits February 5, 2026 09:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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