Skip to content

Optimize data retrieval by using return_path projection - #179

Merged
confluence merged 1 commit into
devfrom
zhenkai/2902_enhance_scripting_api
Sep 7, 2026
Merged

Optimize data retrieval by using return_path projection#179
confluence merged 1 commit into
devfrom
zhenkai/2902_enhance_scripting_api

Conversation

@izkgao

@izkgao izkgao commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

Companion PRs:
CARTAvis/carta-frontend#2924 (should be merged first)
CARTAvis/carta-backend#1624

This PR reduces redundant frontend state traversal by using return_path projections and a type-specific frontend helper, preserving wrapper behavior while minimizing response payloads and Python-side iteration.

What is implemented:

  • Extend return_path documentation and handling descriptions to cover string, list, and mapping projections.
  • Refactor image, color-blending, active-view, region-export, and layer-image lookups to request only the fields they need; use the frontend type helper for color blendings.

Examples:

session.get_value("frames", return_path="frameInfo.fileId")
# [0, 1, 2, 3]

session.get_value("frameMap", return_path=["frameInfo.fileId", "center"])
# {'0': {'center': {'x': 5999.5, 'y': 5999.5}, 'frameInfo.fileId': 0},
#  '1': {'center': {'x': 5999.5, 'y': 5999.5}, 'frameInfo.fileId': 1},
#  '2': {'center': {'x': 5999.5, 'y': 5999.5}, 'frameInfo.fileId': 2},
#  '3': {'center': {'x': 215.5, 'y': 215.5}, 'frameInfo.fileId': 3}}

session.get_value("frameMap", return_path={"fileId": "frameInfo.fileId", "center": "center"})
# {'0': {'center': {'x': 5999.5, 'y': 5999.5}, 'fileId': 0},
#  '1': {'center': {'x': 5999.5, 'y': 5999.5}, 'fileId': 1},
#  '2': {'center': {'x': 5999.5, 'y': 5999.5}, 'fileId': 2},
#  '3': {'center': {'x': 215.5, 'y': 215.5}, 'fileId': 3}}

session.call_action("imageViewConfigStore.getImageIdsByType", ImageType.COLOR_BLENDING, response_expected=True)
# [0]

Frontend now provides improved error handling and descriptive error messages:

session.get_value("frames[0]", return_path=42)
# CartaActionFailed: CARTA scripting action .fetchParameter called with parameters (Macro('', 'frameMap[0]'),) failed: Response path not found: 42

session.get_value("frames", return_path=["frameInfo.fileId", "a_non_existing_path"])
# CartaActionFailed: CARTA scripting action .fetchParameter called with parameters (Macro('', 'frameMap'),) failed: Response path not found: a_non_existing_path

session.get_value("frames", return_path=["frameInfo.fileId", False])
# CartaActionFailed: CARTA scripting action .fetchParameter called with parameters (Macro('', 'frameMap'),) failed: Invalid return path at index 1: expected a string, got false

session.get_value("frames")
# CartaActionFailed: CARTA scripting action .fetchParameter called with parameters (Macro('', 'frameMap'),) failed: Response cannot be serialized to JSON because it contains a circular reference or unsupported value. Use return_path to select JSON-serializable fields.

Checklist

For linked issues (if any):

  • assignee and labels added
  • GitHub Project estimate added

For the pull request:

  • reviewers and assignee added
  • GitHub Project estimate added
  • tests added or updated / no tests needed
  • documentation updated / no documentation update needed

For dependencies and compatibility:

  • companion frontend or backend PRs linked / no companion PRs needed
  • pyproject.toml and uv.lock updated / no dependency changes
  • CARTA compatibility table updated when the minimum CARTA series changes
    or dev starts a new carta-python major/minor series
    / no compatibility
    change

For pull requests targeting main:

  • VERSION.txt finalized for the release
  • final compatibility entry matches the release major/minor version and
    minimum supported CARTA series

@izkgao izkgao added awaiting code review For pull requests that require code review awaiting testing For pull requests that require testing labels Aug 27, 2026
@izkgao
izkgao marked this pull request as ready for review August 27, 2026 07:57
@izkgao izkgao added requiring backend For issues or pull requests that require work in both python and backend requiring frontend For issues or pull requests that require work in both python and frontend labels Aug 27, 2026

@confluence confluence left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. This will eliminate a lot of annoyances! :)

@confluence confluence added awaiting merge For pull requests ready for merge or pending backend/protobuf changes and removed awaiting code review For pull requests that require code review labels Sep 1, 2026
@izkgao

izkgao commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@confluence Now the frontend PR has been merged. The corresponding backend and python PRs could be merged as well when ready.

@confluence
confluence merged commit f69c620 into dev Sep 7, 2026
7 checks passed
@confluence
confluence deleted the zhenkai/2902_enhance_scripting_api branch September 7, 2026 07:19
@confluence confluence removed awaiting merge For pull requests ready for merge or pending backend/protobuf changes awaiting testing For pull requests that require testing labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requiring backend For issues or pull requests that require work in both python and backend requiring frontend For issues or pull requests that require work in both python and frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants