CartoDB/carto-react

Remote executeModel doesn't work for POST requests

efernandezleon opened this issue · 4 comments

Version of C4R: 1.4.3

I want to use the method executeModel to retrieve the data for a formula model in the same way the widgets do in global mode. The issue is that if the payload is too big (and the POST is required) the http call doesn't include the body with the payload and the API returns a 400 error.

Deeping into the code, I can see this method executes makeCall as the final statement as follows:

return makeCall({
  url,
  credentials: source.credentials,
  opts: {
    ...opts,
    method: isGet ? 'GET' : 'POST',
    ...(!isGet && { body: JSON.stringify(queryParams) })
  }
});

You can see how the body is correctly passed as opts properties, but if we dig into the makeCall method, we can see how this is doing nothing with the opts param in the fetch method:

response = await fetch(url.toString(), {
  headers: {
    Authorization: `Bearer ${credentials.accessToken}`
  },
  signal: opts?.abortController?.signal,
  ...opts?.otherOptions,
})

To test this, you can use the following call:

    const data = _executeModel({
      "model": "formula",
      "source": {
          "id": "1ad570b2-ab65-4d38-87f1-8153a5826e06",
          "data": "SELECT * FROM `carto-demo-data.demo_tables.airports` WHERE ST_INTERSECTS(geom, ST_GEOGFROMGEOJSON({\"type\":\"Polygon\",\"coordinates\":[[[-73.97362977542117,40.88551034127466],[-73.9804977096428,40.88525505590902],[-73.98729934431839,40.88449166422513],[-73.99396902447981,40.88322753550163],[-74.0004423778718,40.881474872241135],[-74.00665694027215,40.8792505915634],[-74.01255276176673,40.87657616081757],[-74.0180729879589,40.87347738905398],[-74.02316441036703,40.86998417643237],[-74.02777798059954,40.86613022405908],[-74.0318692832896,40.86195270713292],[-74.03539896321358,40.85749191463605],[-74.03833310250556,40.852790859128255],[-74.04064354440604,40.847894860487415],[-74.04230816053987,40.84285110768259],[-74.04331105930117,40.83770820286829],[-74.04364273352061,40.832515692245714],[-74.04330014620157,40.82732358825008],[-74.04228675372366,40.822181887690256],[-74.04061246652275,40.8171400904888],[-74.0382935478577,40.81224672364775],[-74.03535245186067,40.80754887499792],[-74.03181760263375,40.803091741179756],[-74.02772311669695,40.798918194152385],[-74.02310847160543,40.795068370337134],[-74.0180181240335,40.791579286274704],[-74.01250108106872,40.7884844844132],[-74.00661042886418,40.78581371235102],[-74.00040282316434,40.78359263853708],[-73.99393794654144,40.781842607082204],[-73.98727793746001,40.78058043396701],[-73.98048679652038,40.779818246540906],[-73.97362977542117,40.779563367803384],[-73.96677275432198,40.779818246540906],[-73.95998161338235,40.78058043396701],[-73.95332160430092,40.781842607082204],[-73.94685672767802,40.78359263853708],[-73.94064912197818,40.78581371235102],[-73.93475846977364,40.7884844844132],[-73.92924142680886,40.791579286274704],[-73.92415107923694,40.795068370337134],[-73.91953643414541,40.798918194152385],[-73.91544194820861,40.803091741179756],[-73.91190709898169,40.80754887499792],[-73.90896600298466,40.81224672364775],[-73.90664708431962,40.8171400904888],[-73.9049727971187,40.822181887690256],[-73.90395940464079,40.82732358825008],[-73.90361681732175,40.832515692245714],[-73.90394849154119,40.83770820286829],[-73.90495139030249,40.84285110768259],[-73.90661600643634,40.847894860487415],[-73.9089264483368,40.852790859128255],[-73.91186058762878,40.85749191463605],[-73.91539026755277,40.86195270713292],[-73.91948157024282,40.86613022405908],[-73.92409514047533,40.86998417643237],[-73.92918656288346,40.87347738905398],[-73.93470678907565,40.87657616081757],[-73.94060261057021,40.8792505915634],[-73.94681717297055,40.881474872241135],[-73.95329052636255,40.88322753550163],[-73.95996020652397,40.88449166422513],[-73.96676184119956,40.88525505590902],[-73.97362977542117,40.88551034127466]]]}))",
          "type": "query",
          "credentials": credentials,
          "connection": "carto_dw",
          "filtersLogicalOperator": "and",
          "queryParameters": [],
          "filters": {}
      },
      "params": {
          "column": "*",
          "operation": "count"
      },
      "opts": {}
    })

We have a fix ready for review. I'll ping you when we release a new version published :)

Great!! Thanks @Josmorsot!

hey @efernandezleon, I've just published v1.4.4. Could you try with this new version?

@Josmorsot the fix works like a charm!! Thanks ;)