Skip to content

[Bug] [python][rest] Use the HTTP status when an error response omits code #9983

Description

@Akash3121

Search before asking

  • I searched in the issues and found nothing similar.

Paimon version

master (1d368b4)

Compute Engine

PyPaimon REST client. Engine-independent.

Minimal reproduce step

from pypaimon.api.client import _parse_error_response, DefaultErrorHandler
 
 error = _parse_error_response(
     '{"message":"missing",'
     '"resourceType":"TABLE",'
     '"resourceName":"db.t"}',
     404,
 )
 
 print(error.code)
 DefaultErrorHandler.get_instance().accept(error, "unknown")

Observed behavior:

error.code is None
A generic RESTException is raised instead of NoSuchResourceException.

 _parse_error_response  uses the HTTP status only when parsing fails or when the parsed response has no message. If valid JSON contains a message but omits the optional  code , the parsed object is returned unchanged.

Relevant code:

  •  paimon-python/pypaimon/api/client.py :  _parse_error_response 
  •  paimon-python/pypaimon/api/client.py :  DefaultErrorHandler.accept 

The JVM REST client already falls back to the HTTP status when the parsed error code is null.

What doesn't meet your expectations?

The HTTP status should be used when a valid error response does not contain an application-level code.

A 404 response should map to NoSuchResourceException, a 409 response to AlreadyExistsException, and a 503 response to ServiceUnavailableException.

Returning a generic RESTException can also break catalog operations that rely on typed exceptions for ignore-if-exists or ignore-if-not-exists behavior.

Anything else?

A possible fix is to normalize every successfully parsed response:

 if error.code is None:
     error.code = status_code

The check should use is None, rather than truthiness.

Suggested tests:

  1. Valid error JSON without code for HTTP 404
  2. Valid error JSON without code for HTTP 409
  3. Valid error JSON without code for HTTP 503
  4. End-to-end _execute_request tests asserting the typed exceptions
  5. Catalog-level ignore-if-missing and ignore-if-existing behavior

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions