superset icon indicating copy to clipboard operation
superset copied to clipboard

Superset throws unexpected error while loading filters in a dashboard.

Open Thoufiqkhan opened this issue 1 year ago • 1 comments

Bug description

Supreset ss The above error occurs when loading a dashboard, the filter doesn't seem to load. After a while, sometimes the issue gets resolved. I'm using superset 3.1.1 version and running it on docker in my local.

How to reproduce the bug

  1. Go to dashboards
  2. Click on a dashboard
  3. On loading, the error occurs.

Screenshots/recordings

No response

Superset version

3.1.3

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [ ] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Thoufiqkhan avatar May 24 '24 06:05 Thoufiqkhan

@Thoufiqkhan Hello there! I'm here to help you with any bugs, questions, or becoming a contributor. Let's tackle this together!

To resolve the JavaScript runtime error "Cannot read properties of undefined (reading 'filter')" that occurs while loading filters in an Apache Superset dashboard, you need to ensure that the dataMask object is properly defined and not undefined before calling the filter method on it.

In the provided code, the useNativeFiltersDataMask function is where the filter method is used on dataMask. To prevent the error, you should add a check to ensure dataMask is defined before attempting to use the filter method.

Here is the modified useNativeFiltersDataMask function with the necessary check:

export const useNativeFiltersDataMask = () => {
  const dataMask = useSelector<RootState, DataMaskStateWithId>(
    state => state.dataMask,
  );

  return useMemo(
    () =>
      dataMask
        ? Object.values(dataMask)
            .filter((item: DataMaskWithId) =>
              String(item.id).startsWith(NATIVE_FILTER_PREFIX),
            )
            .reduce(
              (prev, next: DataMaskWithId) => ({ ...prev, [next.id]: next }),
              {},
            ) as DataMaskStateWithId
        : {},
    [dataMask],
  );
};

Additionally, ensure that the dataMask object is correctly initialized and populated in the relevant parts of your codebase. For example, in the createHandleSave function, make sure that the defaultDataMask is set properly:

defaultDataMask: formInputs.defaultDataMask ?? getInitialDataMask(),

Moreover, you can refer to the superset-frontend/src/dashboard/components/nativeFilters/utils.ts file for additional context on how filters are managed and applied in Apache Superset. This file includes functions like getFormData, mergeExtraFormData, and getExtraFormData which handle the form data and extra form data for filters. Ensuring these functions are correctly implemented and that dataMask and other related objects are properly managed can help prevent such runtime errors [1][2][3][4].

Details

About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 24 '24 06:05 dosubot[bot]

Gonna have to close this one, since we no longer support superset 3.x, it's been silent for a very long time, and is largely inactionable since we don't have good reproduction steps here, and most people AFAIK weren't facing this. If you're facing this in 4.1.2 or newer, let us know the updated context and we can reopen.

rusackas avatar Apr 04 '25 00:04 rusackas