Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using select + text/csv output results in wrong csv header #3627

Open
bjornharrtell opened this issue Jun 28, 2024 · 3 comments
Open

Using select + text/csv output results in wrong csv header #3627

bjornharrtell opened this issue Jun 28, 2024 · 3 comments

Comments

@bjornharrtell
Copy link

When using select query string param to reorder and/or omit columns and outpout format text/csv the csv column names header will still be as without select (but data is selected as expected).

@laurenceisla
Copy link
Member

laurenceisla commented Jun 28, 2024

An extra example would be great to further clarify the issue. The request and the expected/wrong responses would be enough, e.g.:

The request:

curl 'localhost:3000/table?select=a,b' -H "Accept: text/csv"

Expected:

expected,csv

Got:

bad,csv

@wolfgangwalther
Copy link
Member

Against our spec fixtures:

A test for regular views/tables:

    it "should respond with CSV with custom select" $
      request methodGet "/projects?select=name,id,client_id&id=eq.2"
              (acceptHdrs "text/csv") ""
        `shouldRespondWith`
        [str|name,id,client_id
            |"Windows 10",2,1|]
        { matchStatus  = 200
        , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"]
        }

A test for RPCs:

      it "returns CSV with custom select" $
        request methodGet "/rpc/getproject?select=name,id,client_id&id=2"
                (acceptHdrs "text/csv") ""
          `shouldRespondWith`
          [str|name,id,client_id
              |"Windows 10",2,1|]
          { matchStatus  = 200
          , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"]
          }

The first test passes, the second test fails:

  1) Feature.Query.RpcSpec, remote procedure call, a proc that returns a set, returns CSV with custom select
       body mismatch:
         expected: "name,id,client_id\n\"Windows 10\",2,1"
         but got:  "client_id,id,name\n\"Windows 10\",2,1"

To get the wrong output you need:

  • call an RPC
  • select columns in non-alphabetic order

The values will be returned in the correct order, but the headers will always be sorted alphabetically.

@bjornharrtell
Copy link
Author

Thank you @wolfgangwalther, this is precisely the issue.

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

No branches or pull requests

3 participants