This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 6329b259 fix(catalog/rest): Handle 204 No Content response in doPost
for renameTable (#633)
6329b259 is described below
commit 6329b2590734489a349f5fa441aafdf802727b44
Author: Ankur Anand <[email protected]>
AuthorDate: Mon Dec 1 02:15:21 2025 +0530
fix(catalog/rest): Handle 204 No Content response in doPost for renameTable
(#633)
Fix `doPost` function to handle `204 No Content` responses, which is the
spec-compliant
response for the `POST /v1/{prefix}/tables/rename` endpoint.
The Iceberg REST Catalog OpenAPI spec defines `renameTable` as returning
`204 No Content`:
```
/v1/{prefix}/tables/rename:
post:
operationId: renameTable
responses:
204:
description: Success, no contentHowever, the current `doPost`
implementation only accepts `200 OK`:
```
Current implementation expected `200` status code:
```
if rsp.StatusCode != http.StatusOK {
return ret, handleNon200(rsp, override)
}
```
This causes `RenameTable` to fail with an empty error when interacting with
spec-compliant REST catalog servers, even though the rename operation
succeeds.
### Related
- Iceberg REST OpenAPI Spec:
https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml
- Similar handling already exists in `do()` function via `allowNoContent`
parameter
---
catalog/rest/rest.go | 12 ++++++++++--
catalog/rest/rest_test.go | 4 ++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index bc56c158..ced05862 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -298,6 +298,10 @@ func doHead(ctx context.Context, baseURI *url.URL, path
[]string, cl *http.Clien
}
func doPost[Payload, Result any](ctx context.Context, baseURI *url.URL, path
[]string, payload Payload, cl *http.Client, override map[int]error) (ret
Result, err error) {
+ return doPostAllowNoContent[Payload, Result](ctx, baseURI, path,
payload, cl, override, false)
+}
+
+func doPostAllowNoContent[Payload, Result any](ctx context.Context, baseURI
*url.URL, path []string, payload Payload, cl *http.Client, override
map[int]error, allowNoContent bool) (ret Result, err error) {
var (
req *http.Request
rsp *http.Response
@@ -320,6 +324,10 @@ func doPost[Payload, Result any](ctx context.Context,
baseURI *url.URL, path []s
return ret, err
}
+ if allowNoContent && rsp.StatusCode == http.StatusNoContent {
+ return ret, err
+ }
+
if rsp.StatusCode != http.StatusOK {
return ret, handleNon200(rsp, override)
}
@@ -926,8 +934,8 @@ func (r *Catalog) RenameTable(ctx context.Context, from, to
table.Identifier) (*
Name: catalog.TableNameFromIdent(to),
}
- _, err := doPost[payload, any](ctx, r.baseURI, []string{"tables",
"rename"}, payload{Source: src, Destination: dst}, r.cl,
- map[int]error{http.StatusNotFound: catalog.ErrNoSuchTable})
+ _, err := doPostAllowNoContent[payload, any](ctx, r.baseURI,
[]string{"tables", "rename"}, payload{Source: src, Destination: dst}, r.cl,
+ map[int]error{http.StatusNotFound: catalog.ErrNoSuchTable},
true)
if err != nil {
return nil, err
}
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index e0463042..5069d192 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -1212,7 +1212,7 @@ func (r *RestCatalogSuite) TestLoadTable200() {
}))
}
-func (r *RestCatalogSuite) TestRenameTable200() {
+func (r *RestCatalogSuite) TestRenameTable204() {
// Mock the rename table endpoint
r.mux.HandleFunc("/v1/tables/rename", func(w http.ResponseWriter, req
*http.Request) {
r.Require().Equal(http.MethodPost, req.Method)
@@ -1237,7 +1237,7 @@ func (r *RestCatalogSuite) TestRenameTable200() {
r.Equal([]string{"fokko"}, payload.Destination.Namespace)
r.Equal("destination", payload.Destination.Name)
- w.WriteHeader(http.StatusOK)
+ w.WriteHeader(http.StatusNoContent)
})
// Mock the get table endpoint for loading the renamed table