Skip to content

Commit

Permalink
fix(frontend): allow "constructor" property in response data (#25407)
Browse files Browse the repository at this point in the history
(cherry picked from commit a1983e4)
  • Loading branch information
SpencerTorres authored and michael-s-molina committed Apr 8, 2024
1 parent cb39fcd commit b1d355e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import { cloneDeepWith } from 'lodash';

import { ParseMethod, TextResponse, JsonResponse } from '../types';

const JSONbig = _JSONbig({
constructorAction: 'preserve',
});

export default async function parseResponse<T extends ParseMethod = 'json'>(
apiPromise: Promise<Response>,
parseMethod?: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ describe('parseResponse()', () => {

it('resolves to big number value if `parseMethod=json-bigint`', async () => {
const mockBigIntUrl = '/mock/get/bigInt';
const mockGetBigIntPayload =
'{ "value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" }, "number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 } }';
const mockGetBigIntPayload = `{
"value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" },
"number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 },
"string.constructor": "data.constructor",
"constructor": "constructor"
}`;
fetchMock.get(mockBigIntUrl, mockGetBigIntPayload);
const responseBigNumber = await parseResponse(
callApi({ url: mockBigIntUrl, method: 'GET' }),
Expand All @@ -167,6 +171,10 @@ describe('parseResponse()', () => {
expect(Math.abs(responseBigNumber.json.floatValue.minus)).toEqual(
responseBigNumber.json.floatValue.plus,
);
expect(responseBigNumber.json['string.constructor']).toEqual(
'data.constructor',
);
expect(responseBigNumber.json.constructor).toEqual('constructor');
});

it('rejects if request.ok=false', async () => {
Expand Down
7 changes: 6 additions & 1 deletion superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import React, { useEffect, useRef, useState, useMemo } from 'react';
import { getMultipleTextDimensions, styled } from '@superset-ui/core';
import { useDebounceValue } from 'src/hooks/useDebounceValue';
import { useCellContentParser } from './useCellContentParser';
import { renderResultCell } from './utils';
import { Table, TableSize } from '../Table';

const JSONbig = _JSONbig({
storeAsString: true,
constructorAction: 'preserve',
});

const SCROLL_BAR_HEIGHT = 15;
// This regex handles all possible number formats in javascript, including ints, floats,
// exponential notation, NaN, and Infinity.
Expand Down
2 changes: 1 addition & 1 deletion superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from sqlalchemy import and_
from sqlglot import exp, parse, parse_one
from sqlglot.dialects import Dialects
from sqlglot.errors import SqlglotError
from sqlglot.errors import ParseError, SqlglotError
from sqlglot.optimizer.scope import Scope, ScopeType, traverse_scope
from sqlparse import keywords
from sqlparse.lexer import Lexer
Expand Down

0 comments on commit b1d355e

Please sign in to comment.