mirror of
https://github.com/apache/superset.git
synced 2024-09-12 16:49:40 -04:00
fix(frontend): allow "constructor" property in response data (#25407)
(cherry picked from commit a1983e468b
)
This commit is contained in:
parent
cb39fcd67d
commit
23cd2b138b
@ -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,
|
||||
|
@ -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' }),
|
||||
@ -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 () => {
|
||||
|
@ -16,7 +16,7 @@
|
||||
* 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';
|
||||
@ -24,6 +24,11 @@ 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.
|
||||
|
@ -31,7 +31,7 @@ from jinja2 import nodes
|
||||
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
|
||||
|
@ -1479,7 +1479,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
"indexes": [],
|
||||
"name": "wrong_table",
|
||||
"primaryKey": {"constrained_columns": None, "name": None},
|
||||
"selectStar": "SELECT\n *\nFROM wrong_table\nLIMIT 100\nOFFSET 0",
|
||||
"selectStar": "SELECT *\nFROM wrong_table\nLIMIT 100\nOFFSET 0",
|
||||
},
|
||||
)
|
||||
elif example_db.backend == "mysql":
|
||||
|
Loading…
Reference in New Issue
Block a user