You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "ngokturkkarli (via GitHub)" <gi...@apache.org> on 2025/09/28 18:33:51 UTC

[PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

ngokturkkarli opened a new pull request, #35317:
URL: https://github.com/apache/superset/pull/35317

   ### SUMMARY
   This PR fixes circular dependency issues in dashboard native filters and improves dependency handling. The changes include:
   
   ### TESTING INSTRUCTIONS
   - Open dashboard → click "Add or edit filters" button
   - Create Filter A and Filter B
   - Set Filter A to depend on Filter B
   - Try to set Filter B to depend on Filter A - this should be prevented
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: https://github.com/apache/superset/issues/33908
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35317:
URL: https://github.com/apache/superset/pull/35317#issuecomment-3436207772

   šŸŽŖ [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18745446184) for [a7d8e76](https://github.com/apache/superset/commit/a7d8e76)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "ngokturkkarli (via GitHub)" <gi...@apache.org>.
ngokturkkarli commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2453110239


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DependencyList.tsx:
##########
@@ -189,19 +189,43 @@ const DependencyList = ({
   const hasAvailableFilters = availableFilters.length > 0;
   const hasDependencies = dependencies.length > 0;
 
+  // Clean up invalid dependencies when available filters change
+  useEffect(() => {
+    if (dependencies.length > 0) {
+      const availableFilterIds = new Set(availableFilters.map(f => f.value));
+      const validDependencies = dependencies.filter(dep =>
+        availableFilterIds.has(dep),
+      );
+
+      // If some dependencies are no longer valid, update the list
+      if (validDependencies.length !== dependencies.length) {
+        onDependenciesChange(validDependencies);
+      }
+    }
+  }, [availableFilters, dependencies, onDependenciesChange]);
+
   const onCheckChanged = (value: boolean) => {
-    const newDependencies: string[] = [];
-    if (value && !hasDependencies && hasAvailableFilters) {
-      newDependencies.push(getDependencySuggestion());
+    if (value) {
+      // When enabling dependencies, add a suggestion if no dependencies exist
+      if (!hasDependencies && hasAvailableFilters) {
+        const suggestion = getDependencySuggestion();
+        if (suggestion) {
+          onDependenciesChange([suggestion]);
+        }
+      }
+      // If no available filters or suggestion, keep the checkbox checked but with empty dependencies
+      // This prevents the checkbox from immediately closing due to lack of available filters
+    } else {
+      // When disabling dependencies, clear all dependencies
+      onDependenciesChange([]);

Review Comment:
   Nice catch! fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "ngokturkkarli (via GitHub)" <gi...@apache.org>.
ngokturkkarli commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2456985783


##########
superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts:
##########
@@ -160,6 +160,57 @@ describe('Native filters', () => {
       );
     });
 
+    it('user cannot create bi-directional dependencies between filters', () => {
+      prepareDashboardFilters([
+        { name: 'region', column: 'region', datasetId: 2 },
+        { name: 'country_name', column: 'country_name', datasetId: 2 },
+        { name: 'country_code', column: 'country_code', datasetId: 2 },
+        { name: 'year', column: 'year', datasetId: 2 },
+      ]);
+      enterNativeFilterEditModal();
+
+      // First, make country_name dependent on region
+      selectFilter(1);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+        },
+      );
+      addParentFilterWithValue(0, testItems.topTenChart.filterColumnRegion);
+
+      // Second, make country_code dependent on country_name
+      selectFilter(2);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+        },
+      );
+      addParentFilterWithValue(0, testItems.topTenChart.filterColumn);
+
+      // Now select region filter and try to add dependency
+      selectFilter(0);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+
+          // Verify that only 'year' is available as dependency for region
+          // 'country_name' and 'country_code' should not be available (would create circular dependency)
+          cy.get('input[aria-label^="Limit type"]').click({ force: true });
+          cy.get('.ant-select-dropdown').should('be.visible');
+          cy.get('.ant-select-dropdown').should('contain', 'year');
+          cy.get('.ant-select-dropdown').should('not.contain', 'country_name');
+          cy.get('.ant-select-dropdown').should('not.contain', 'country_code');
+          cy.get('.ant-select-dropdown').contains('year').click();

Review Comment:
   Sure, we can use it. It is fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2442441964


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:
##########
@@ -584,7 +584,10 @@ const FiltersConfigForm = (
     return Promise.reject(new Error(t('Pre-filter is required')));
   };
 
-  const availableFilters = getAvailableFilters(filterId);
+  const availableFilters = useMemo(
+    () => getAvailableFilters(filterId),
+    [getAvailableFilters, filterId, filters],
+  );

Review Comment:
   ### Memoization dependency mismatch with function parameters <sub>![category Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The useMemo dependency array includes `filters` but the memoized function `getAvailableFilters(filterId)` only takes `filterId` as a parameter, creating a potential mismatch between dependencies and actual function inputs.
   
   
   ###### Why this matters
   This could lead to unnecessary re-computations when `filters` changes but `getAvailableFilters` doesn't actually use the updated filters data, or conversely, stale memoized results if `getAvailableFilters` internally depends on filters data that isn't reflected in its parameters.
   
   ###### Suggested change āˆ™ *Feature Preview*
   Verify that `getAvailableFilters` function signature matches its actual dependencies. If it internally uses `filters` data, it should accept it as a parameter:
   
   ```typescript
   const availableFilters = useMemo(
     () => getAvailableFilters(filterId, filters),
     [getAvailableFilters, filterId, filters],
   );
   ```
   
   Or if `filters` is not needed, remove it from dependencies:
   
   ```typescript
   const availableFilters = useMemo(
     () => getAvailableFilters(filterId),
     [getAvailableFilters, filterId],
   );
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/šŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c18b0ece-49a4-4ee5-bf09-f8b0ee90da58/upvote) [![Incorrect](https://img.shields.io/badge/šŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c18b0ece-49a4-4ee5-bf09-f8b0ee90da58?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/šŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c18b0ece-49a4-4ee5-bf09-f8b0ee90da58?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/šŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c18b0ece-49a4-4ee5-bf09-f8b0ee90da58?what_not_in_standard=true) [![Other](https://img.shields.io/badge/šŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c18b0ece-49a4-4ee5-bf09-f8b0ee90da58)
   </details>
   
   <sub>
   
   šŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:e0c66099-e590-47ee-921a-c6fce21b37e4 -->
   
   
   [](e0c66099-e590-47ee-921a-c6fce21b37e4)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2442444019


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DependencyList.tsx:
##########
@@ -189,19 +189,43 @@ const DependencyList = ({
   const hasAvailableFilters = availableFilters.length > 0;
   const hasDependencies = dependencies.length > 0;
 
+  // Clean up invalid dependencies when available filters change
+  useEffect(() => {
+    if (dependencies.length > 0) {
+      const availableFilterIds = new Set(availableFilters.map(f => f.value));
+      const validDependencies = dependencies.filter(dep =>
+        availableFilterIds.has(dep),
+      );
+
+      // If some dependencies are no longer valid, update the list
+      if (validDependencies.length !== dependencies.length) {
+        onDependenciesChange(validDependencies);
+      }
+    }
+  }, [availableFilters, dependencies, onDependenciesChange]);
+
   const onCheckChanged = (value: boolean) => {
-    const newDependencies: string[] = [];
-    if (value && !hasDependencies && hasAvailableFilters) {
-      newDependencies.push(getDependencySuggestion());
+    if (value) {
+      // When enabling dependencies, add a suggestion if no dependencies exist
+      if (!hasDependencies && hasAvailableFilters) {
+        const suggestion = getDependencySuggestion();
+        if (suggestion) {
+          onDependenciesChange([suggestion]);
+        }
+      }
+      // If no available filters or suggestion, keep the checkbox checked but with empty dependencies
+      // This prevents the checkbox from immediately closing due to lack of available filters
+    } else {
+      // When disabling dependencies, clear all dependencies
+      onDependenciesChange([]);

Review Comment:
   This seems unneccessary. Can we revert this?



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DependencyList.tsx:
##########
@@ -189,19 +189,43 @@ const DependencyList = ({
   const hasAvailableFilters = availableFilters.length > 0;
   const hasDependencies = dependencies.length > 0;
 
+  // Clean up invalid dependencies when available filters change
+  useEffect(() => {
+    if (dependencies.length > 0) {
+      const availableFilterIds = new Set(availableFilters.map(f => f.value));
+      const validDependencies = dependencies.filter(dep =>
+        availableFilterIds.has(dep),
+      );
+
+      // If some dependencies are no longer valid, update the list
+      if (validDependencies.length !== dependencies.length) {
+        onDependenciesChange(validDependencies);
+      }
+    }
+  }, [availableFilters, dependencies, onDependenciesChange]);
+
   const onCheckChanged = (value: boolean) => {
-    const newDependencies: string[] = [];
-    if (value && !hasDependencies && hasAvailableFilters) {
-      newDependencies.push(getDependencySuggestion());
+    if (value) {
+      // When enabling dependencies, add a suggestion if no dependencies exist
+      if (!hasDependencies && hasAvailableFilters) {
+        const suggestion = getDependencySuggestion();
+        if (suggestion) {
+          onDependenciesChange([suggestion]);
+        }
+      }
+      // If no available filters or suggestion, keep the checkbox checked but with empty dependencies
+      // This prevents the checkbox from immediately closing due to lack of available filters
+    } else {
+      // When disabling dependencies, clear all dependencies
+      onDependenciesChange([]);
     }
-    onDependenciesChange(newDependencies);
   };
 
   return (
     <MainPanel>
       <CollapsibleControl
         title={t('Values are dependent on other filters')}
-        initialValue={hasDependencies}
+        checked={hasDependencies}

Review Comment:
   Are we making this component controlled now?



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:
##########
@@ -584,7 +584,10 @@ const FiltersConfigForm = (
     return Promise.reject(new Error(t('Pre-filter is required')));
   };
 
-  const availableFilters = getAvailableFilters(filterId);
+  const availableFilters = useMemo(
+    () => getAvailableFilters(filterId),
+    [getAvailableFilters, filterId, filters],
+  );

Review Comment:
   Do we need useMemo here? I don't think it improves performance that much.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35317:
URL: https://github.com/apache/superset/pull/35317#issuecomment-3436243820

   šŸŽŖ [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18745446184) for [a7d8e76](https://github.com/apache/superset/commit/a7d8e76)
   
   • **Environment:** http://52.88.47.227:8080 (admin/admin)
   • **Lifetime:** 48h auto-cleanup
   • **Updates:** New commits create fresh environments automatically


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2454655596


##########
superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts:
##########
@@ -160,6 +160,57 @@ describe('Native filters', () => {
       );
     });
 
+    it('user cannot create bi-directional dependencies between filters', () => {
+      prepareDashboardFilters([
+        { name: 'region', column: 'region', datasetId: 2 },
+        { name: 'country_name', column: 'country_name', datasetId: 2 },
+        { name: 'country_code', column: 'country_code', datasetId: 2 },
+        { name: 'year', column: 'year', datasetId: 2 },
+      ]);
+      enterNativeFilterEditModal();
+
+      // First, make country_name dependent on region
+      selectFilter(1);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+        },
+      );
+      addParentFilterWithValue(0, testItems.topTenChart.filterColumnRegion);
+
+      // Second, make country_code dependent on country_name
+      selectFilter(2);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+        },
+      );
+      addParentFilterWithValue(0, testItems.topTenChart.filterColumn);
+
+      // Now select region filter and try to add dependency
+      selectFilter(0);
+      cy.get(nativeFilters.filterConfigurationSections.displayedSection).within(
+        () => {
+          cy.contains('Values are dependent on other filters')
+            .should('be.visible')
+            .click();
+
+          // Verify that only 'year' is available as dependency for region
+          // 'country_name' and 'country_code' should not be available (would create circular dependency)
+          cy.get('input[aria-label^="Limit type"]').click({ force: true });
+          cy.get('.ant-select-dropdown').should('be.visible');
+          cy.get('.ant-select-dropdown').should('contain', 'year');
+          cy.get('.ant-select-dropdown').should('not.contain', 'country_name');
+          cy.get('.ant-select-dropdown').should('not.contain', 'country_code');
+          cy.get('.ant-select-dropdown').contains('year').click();

Review Comment:
   Can we use more solid selectors? Maybe data-test or a combination of role-label



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "geido (via GitHub)" <gi...@apache.org>.
geido merged PR #35317:
URL: https://github.com/apache/superset/pull/35317


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2386264098


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx:
##########
@@ -361,16 +361,49 @@ function FiltersConfigModal({
   );
 
   const getAvailableFilters = useCallback(
-    (filterId: string) =>
-      filterIds
+    (filterId: string) => {
+      // Build current dependency map
+      const dependencyMap = new Map<string, string[]>();
+      const filters = form.getFieldValue('filters');
+      if (filters) {
+        Object.keys(filters).forEach(key => {
+          const formItem = filters[key];
+          const configItem = filterConfigMap[key];
+          let array: string[] = [];
+          if (formItem && 'dependencies' in formItem) {
+            array = [...formItem.dependencies];
+          } else if (configItem?.cascadeParentIds) {
+            array = [...configItem.cascadeParentIds];
+          }
+          dependencyMap.set(key, array);
+        });

Review Comment:
   ### Unnecessary array copying in dependency map <sub>![category Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code creates unnecessary array copies with spread operator for every filter when building the dependency map.
   
   
   ###### Why this matters
   Creating new arrays with the spread operator for each filter adds memory allocation overhead and garbage collection pressure, especially when dealing with many filters.
   
   ###### Suggested change āˆ™ *Feature Preview*
   Directly assign the arrays without copying since they're not being mutated:
   
   ```typescript
   Object.keys(filters).forEach(key => {
     const formItem = filters[key];
     const configItem = filterConfigMap[key];
     let array: string[] = [];
     if (formItem && 'dependencies' in formItem) {
       array = formItem.dependencies || [];
     } else if (configItem?.cascadeParentIds) {
       array = configItem.cascadeParentIds;
     }
     dependencyMap.set(key, array);
   });
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/šŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2bd32934-e5a2-46f6-bebf-25ed5c69f3c2/upvote) [![Incorrect](https://img.shields.io/badge/šŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2bd32934-e5a2-46f6-bebf-25ed5c69f3c2?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/šŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2bd32934-e5a2-46f6-bebf-25ed5c69f3c2?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/šŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2bd32934-e5a2-46f6-bebf-25ed5c69f3c2?what_not_in_standard=true) [![Other](https://img.shields.io/badge/šŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2bd32934-e5a2-46f6-bebf-25ed5c69f3c2)
   </details>
   
   <sub>
   
   šŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:676f9b2e-a363-415b-8915-2a01e1b79fe3 -->
   
   
   [](676f9b2e-a363-415b-8915-2a01e1b79fe3)



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:
##########
@@ -584,7 +584,10 @@ const FiltersConfigForm = (
     return Promise.reject(new Error(t('Pre-filter is required')));
   };
 
-  const availableFilters = getAvailableFilters(filterId);
+  const availableFilters = useMemo(
+    () => getAvailableFilters(filterId),
+    [getAvailableFilters, filterId, filters],
+  );

Review Comment:
   ### Overly broad useMemo dependencies <sub>![category Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The useMemo dependency array includes `filters` but `getAvailableFilters` function may not actually depend on the entire `filters` object, potentially causing unnecessary re-computations.
   
   
   ###### Why this matters
   This could lead to performance issues where the memoized value is recalculated more frequently than needed, defeating the purpose of memoization and potentially causing UI flickering or lag during filter configuration.
   
   ###### Suggested change āˆ™ *Feature Preview*
   Review what specific parts of `filters` the `getAvailableFilters` function actually uses and include only those specific dependencies, or remove `filters` if it's not actually used by the function:
   
   ```typescript
   const availableFilters = useMemo(
     () => getAvailableFilters(filterId),
     [getAvailableFilters, filterId], // Remove filters if not needed
   );
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/šŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/1e5887af-1602-4399-86a1-14d56180852d/upvote) [![Incorrect](https://img.shields.io/badge/šŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/1e5887af-1602-4399-86a1-14d56180852d?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/šŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/1e5887af-1602-4399-86a1-14d56180852d?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/šŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/1e5887af-1602-4399-86a1-14d56180852d?what_not_in_standard=true) [![Other](https://img.shields.io/badge/šŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/1e5887af-1602-4399-86a1-14d56180852d)
   </details>
   
   <sub>
   
   šŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:a75464f1-abee-4ca2-9f22-d10faf87d1ef -->
   
   
   [](a75464f1-abee-4ca2-9f22-d10faf87d1ef)



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:
##########
@@ -918,7 +921,8 @@ const FiltersConfigForm = (
                             children: (
                               <>
                                 {canDependOnOtherFilters &&
-                                  hasAvailableFilters && (
+                                  (hasAvailableFilters ||
+                                    dependencies.length > 0) && (

Review Comment:
   ### Inconsistent dependency UI state <sub>![category Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The condition allows rendering dependency UI when `dependencies.length > 0` even if there are no available filters, which could lead to a confusing user experience where dependencies are shown but cannot be modified.
   
   
   ###### Why this matters
   Users might see existing dependencies but be unable to add, remove, or modify them if no filters are available, creating an inconsistent and potentially frustrating interface state.
   
   ###### Suggested change āˆ™ *Feature Preview*
   Consider separating the logic to handle existing dependencies differently from adding new ones, or provide clear messaging when dependencies exist but cannot be modified:
   
   ```typescript
   {canDependOnOtherFilters && (
     hasAvailableFilters ? (
       // Full dependency management UI
       <DependencyList ... />
     ) : dependencies.length > 0 ? (
       // Read-only view of existing dependencies with explanation
       <ReadOnlyDependencyList dependencies={dependencies} />
     ) : null
   )}
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/šŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eb17f215-9c67-4b9e-8041-4764b2288396/upvote) [![Incorrect](https://img.shields.io/badge/šŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eb17f215-9c67-4b9e-8041-4764b2288396?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/šŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eb17f215-9c67-4b9e-8041-4764b2288396?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/šŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eb17f215-9c67-4b9e-8041-4764b2288396?what_not_in_standard=true) [![Other](https://img.shields.io/badge/šŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eb17f215-9c67-4b9e-8041-4764b2288396)
   </details>
   
   <sub>
   
   šŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:ee752082-5e6d-49be-ae5e-565723eaacfb -->
   
   
   [](ee752082-5e6d-49be-ae5e-565723eaacfb)



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx:
##########
@@ -361,16 +361,49 @@ function FiltersConfigModal({
   );
 
   const getAvailableFilters = useCallback(
-    (filterId: string) =>
-      filterIds
+    (filterId: string) => {
+      // Build current dependency map
+      const dependencyMap = new Map<string, string[]>();
+      const filters = form.getFieldValue('filters');
+      if (filters) {
+        Object.keys(filters).forEach(key => {
+          const formItem = filters[key];
+          const configItem = filterConfigMap[key];
+          let array: string[] = [];
+          if (formItem && 'dependencies' in formItem) {
+            array = [...formItem.dependencies];
+          } else if (configItem?.cascadeParentIds) {
+            array = [...configItem.cascadeParentIds];
+          }
+          dependencyMap.set(key, array);
+        });
+      }
+
+      return filterIds
         .filter(id => id !== filterId)
         .filter(id => canBeUsedAsDependency(id))
+        .filter(id => {
+          // Check if adding this dependency would create a circular dependency
+          const currentDependencies = dependencyMap.get(filterId) || [];
+          const testDependencies = [...currentDependencies, id];
+          const testMap = new Map(dependencyMap);
+          testMap.set(filterId, testDependencies);

Review Comment:
   ### Inefficient circular dependency checking <sub>![category Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Creating a new Map and array for each filter being tested for circular dependencies results in O(n²) space complexity and unnecessary object creation.
   
   
   ###### Why this matters
   This approach creates significant memory overhead when filtering many potential dependencies, as it creates a full copy of the dependency map for each candidate filter.
   
   ###### Suggested change āˆ™ *Feature Preview*
   Optimize by temporarily modifying the original map and restoring it, or implement a more efficient cycle detection algorithm that doesn't require full map copying:
   
   ```typescript
   .filter(id => {
     // Temporarily add the dependency to check for cycles
     const currentDependencies = dependencyMap.get(filterId) || [];
     dependencyMap.set(filterId, [...currentDependencies, id]);
     const hasCycle = hasCircularDependency(dependencyMap, filterId);
     // Restore original state
     dependencyMap.set(filterId, currentDependencies);
     return !hasCycle;
   })
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/šŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/10d7aac2-3de3-4a9e-ba6e-e6c4a56ba047/upvote) [![Incorrect](https://img.shields.io/badge/šŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/10d7aac2-3de3-4a9e-ba6e-e6c4a56ba047?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/šŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/10d7aac2-3de3-4a9e-ba6e-e6c4a56ba047?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/šŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/10d7aac2-3de3-4a9e-ba6e-e6c4a56ba047?what_not_in_standard=true) [![Other](https://img.shields.io/badge/šŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/10d7aac2-3de3-4a9e-ba6e-e6c4a56ba047)
   </details>
   
   <sub>
   
   šŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:0d645211-42e9-4cec-a860-f1dd2db6267f -->
   
   
   [](0d645211-42e9-4cec-a860-f1dd2db6267f)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "ngokturkkarli (via GitHub)" <gi...@apache.org>.
ngokturkkarli commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2453069154


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DependencyList.tsx:
##########
@@ -189,19 +189,43 @@ const DependencyList = ({
   const hasAvailableFilters = availableFilters.length > 0;
   const hasDependencies = dependencies.length > 0;
 
+  // Clean up invalid dependencies when available filters change
+  useEffect(() => {
+    if (dependencies.length > 0) {
+      const availableFilterIds = new Set(availableFilters.map(f => f.value));
+      const validDependencies = dependencies.filter(dep =>
+        availableFilterIds.has(dep),
+      );
+
+      // If some dependencies are no longer valid, update the list
+      if (validDependencies.length !== dependencies.length) {
+        onDependenciesChange(validDependencies);
+      }
+    }
+  }, [availableFilters, dependencies, onDependenciesChange]);
+
   const onCheckChanged = (value: boolean) => {
-    const newDependencies: string[] = [];
-    if (value && !hasDependencies && hasAvailableFilters) {
-      newDependencies.push(getDependencySuggestion());
+    if (value) {
+      // When enabling dependencies, add a suggestion if no dependencies exist
+      if (!hasDependencies && hasAvailableFilters) {
+        const suggestion = getDependencySuggestion();
+        if (suggestion) {
+          onDependenciesChange([suggestion]);
+        }
+      }
+      // If no available filters or suggestion, keep the checkbox checked but with empty dependencies
+      // This prevents the checkbox from immediately closing due to lack of available filters
+    } else {
+      // When disabling dependencies, clear all dependencies
+      onDependenciesChange([]);
     }
-    onDependenciesChange(newDependencies);
   };
 
   return (
     <MainPanel>
       <CollapsibleControl
         title={t('Values are dependent on other filters')}
-        initialValue={hasDependencies}
+        checked={hasDependencies}

Review Comment:
   Without controlled behavior, when dependencies are auto-cleaned, the checkbox wouldn't reflect that change. That's why I made it controlled.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "ngokturkkarli (via GitHub)" <gi...@apache.org>.
ngokturkkarli commented on code in PR #35317:
URL: https://github.com/apache/superset/pull/35317#discussion_r2453220305


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx:
##########
@@ -584,7 +584,10 @@ const FiltersConfigForm = (
     return Promise.reject(new Error(t('Pre-filter is required')));
   };
 
-  const availableFilters = getAvailableFilters(filterId);
+  const availableFilters = useMemo(
+    () => getAvailableFilters(filterId),
+    [getAvailableFilters, filterId, filters],
+  );

Review Comment:
   I think "availableFilters" must change only when these dependencies change. So, useMemo usage is okey. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(native-filters): prevent circular dependencies and improve dependency handling [superset]

Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on PR #35317:
URL: https://github.com/apache/superset/pull/35317#issuecomment-3437318226

   It looks like the ci is failing and you need to run prettier


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org