Skip to content

fix(python-sdk): keep raw mo_ctl output when the reply is not JSON - #31524

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/31384-moctl-raw-output
Oct 28, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/31384-moctl-raw-output

Conversation

@MatrixAdventurer

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #31384

What this PR does / why we need it:

The escaping parts of #31384 are already fixed on main (#31262 for metadata_scan and #31322 for _build_moctl_sql; see the issue comment). This PR fixes what is left: expected behavior #2, a non-JSON mo_ctl reply.

Root cause.

  1. _execute_moctl (sync in moctl.py, async in async_client.py) called json.loads(result_str) directly. On a plain-text reply it raised MoCtlError("Failed to parse mo_ctl result: Expecting value: line 1 column 1 (char 0)"), and the server's actual output was lost.
  2. A MoCtlError raised inside the try block (no rows, or a returnStr other than OK) was caught again by except Exception and re-wrapped, so the message read mo_ctl operation failed: mo_ctl operation failed: table not found. In the async manager the same re-wrap also hid the JSON error behind the generic prefix.

Fix.

  • New _decode_moctl_result() in moctl.py, shared by both managers. On non-JSON it raises the manager's own MoCtlError class: the sync manager uses matrixone.moctl.MoCtlError and the async manager uses matrixone.exceptions.MoCtlError, as before.
  • The error message includes a raw-output preview (capped at 500 chars). The full text is available as error.raw_output.
  • except MoCtlError: raise lets SDK errors pass through unwrapped. Other exceptions are still wrapped as before.

Tests (tests/offline/test_moctl.py):

  • test_execute_moctl_non_json_keeps_raw_output: a sync plain-text reply keeps the raw text in the message and in raw_output.
  • test_async_execute_moctl_non_json_keeps_raw_output: the same check for the async manager.
  • test_execute_moctl_failed_return_str_is_not_double_wrapped: the message is exactly mo_ctl operation failed: table not found.

Results:

  • Before the fix, all 3 new tests fail (the actual message was mo_ctl operation failed: mo_ctl operation failed: table not found). After the fix, all 3 pass.
  • test_moctl.py + test_moctl_simple.py: 26 passed.
  • pytest tests/offline (Python 3.13, run locally): 2289 passed, 95 subtests passed.
  • black --check is clean. flake8 reports no new warnings (4 before, 4 after; all are existing unused imports in async_client.py).

3 files, +61/-9.

本操作由 LW 授权的 Grok Bot 智能体执行

A non-JSON mo_ctl reply raised MoCtlError with only the JSON decoder
message, so callers could not see what the server actually returned.
MoCtlErrors raised inside the try block (no rows, failed returnStr)
were also re-wrapped by the generic handler, producing
"mo_ctl operation failed: mo_ctl operation failed: ...".

Decode through one shared helper that puts a raw-output preview in the
message and the full text on error.raw_output, and let MoCtlError pass
through unwrapped, in both the sync and async managers.

Refs matrixorigin#31384
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 28, 2026
@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: ac62eb154ee28e4b7e72c46a6cb39a754ba9dfc1

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: ac62eb154ee28e4b7e72c46a6cb39a754ba9dfc1

Assessment: approve

The complete delta preserves non-JSON output with a bounded preview, retains existing exception classes, and prevents double wrapping. This matches the linked issue’s follow-up decision. No actionable defects or unresolved discussion concerns remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • 28 focused repository tests passed; moctl-tests.log matches checks/1793165593676580840-3.json.

  • 27 diagnostic cases passed, covering preview bounds, raw-output retention, public methods, error identity, causes and cancellation; moctl-probe.log matches checks/1793165681024883415-3.json.

  • Frozen-base controls reproduced lost raw text and double wrapping while preserving successful JSON results; base-control.log matches checks/1793165680878279851-3.json.

  • git diff --check passed. Verified clean frozen source and reconciled receipts, logs and discussion coverage. Records are in /home/xupeng/.local/state/mo-bot/jobs/a8547b11a6f32bff24c84777/attempt-1/discussion-assessment.json and validation-manifest.json; audit receipt: checks/1793165806807820876-4.json.

Limitations:

  • Executed with Python 3.13.5 and SQLAlchemy 2.1.6 using mocked transport. No live-server run, full offline suite or multi-version matrix was performed; native result production was source-traced.

@mergify mergify Bot added the queued label Oct 28, 2026
@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as f97056d at 05:59 UTC

22 min in the queue, 2 min of it CI.

So far

  • ✅ Entered the queue Wed 28 Oct, 05:38 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 05:59 · f97056d · squash
Merge conditions: 3 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
✅ any of: check-success = CI Required, check-neutral = CI Required, check-skipped = CI Required GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot requested a review from aptend as a code owner October 28, 2026 05:57
@mergify
mergify Bot merged commit f97056d into matrixorigin:main Oct 28, 2026
29 of 30 checks passed
@mergify mergify Bot removed the queued label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: metadata_scan and moctl interpolate args unescaped; moctl hard-crashes on non-JSON output

2 participants