You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2025/12/17 22:29:28 UTC

(superset) branch new-dar updated (b469b01e0f -> 902509b1f0)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch new-dar
in repository https://gitbox.apache.org/repos/asf/superset.git


    from b469b01e0f Initial UI
     new 3554325104 Testing
     new 2e7df4614c RLS and CLS working
     new 902509b1f0 Explore working

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 superset/data_access_rules/api.py     |  79 +++++++++++-
 superset/data_access_rules/schemas.py |  13 +-
 superset/data_access_rules/utils.py   | 237 +++++++++++++++++++++++++++++++++-
 superset/databases/filters.py         |  18 ++-
 superset/security/manager.py          |  68 ++++++++++
 superset/sql/parse.py                 |   3 +
 superset/utils/filters.py             |  47 ++++++-
 7 files changed, 454 insertions(+), 11 deletions(-)


(superset) 03/03: Explore working

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch new-dar
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 902509b1f06302f1adb7e559fe2f1f22f3842275
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Dec 17 17:29:18 2025 -0500

    Explore working
---
 superset/data_access_rules/utils.py | 57 +++++++++++++++++++++++++++++++++++++
 superset/security/manager.py        | 23 +++++++++++++++
 superset/utils/filters.py           | 47 +++++++++++++++++++++++++++++-
 3 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/superset/data_access_rules/utils.py b/superset/data_access_rules/utils.py
index 90582b7291..c56d9268f2 100644
--- a/superset/data_access_rules/utils.py
+++ b/superset/data_access_rules/utils.py
@@ -732,6 +732,63 @@ def get_allowed_databases() -> set[str]:
     return database_names
 
 
+@dataclass
+class AllowedTable:
+    """A table allowed by DAR with database context."""
+
+    database: str
+    table: str
+    schema: str | None = None
+    catalog: str | None = None
+
+
+def get_all_allowed_tables() -> list[AllowedTable]:
+    """
+    Get all tables that the current user has access to via Data Access Rules
+    across all databases.
+
+    This function is used for dataset filtering where we need to know all
+    specific tables the user can access.
+
+    Returns:
+        List of AllowedTable objects representing allowed tables.
+    """
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return []
+
+    rules = get_user_rules()
+    if not rules:
+        return []
+
+    allowed_tables: list[AllowedTable] = []
+
+    for rule in rules:
+        rule_dict = rule.rule_dict
+
+        # Collect tables from allowed entries
+        for entry in rule_dict.get("allowed", []):
+            database = entry.get("database")
+            if not database:
+                continue
+
+            table_name = entry.get("table")
+            if not table_name:
+                # Skip database-level or schema-level access for now
+                # as we can't enumerate all tables without querying the DB
+                continue
+
+            allowed_tables.append(
+                AllowedTable(
+                    database=database,
+                    table=table_name,
+                    schema=entry.get("schema"),
+                    catalog=entry.get("catalog"),
+                )
+            )
+
+    return allowed_tables
+
+
 def get_all_group_keys(
     database_name: str | None = None,
     table: Table | None = None,
diff --git a/superset/security/manager.py b/superset/security/manager.py
index f377832194..5c48064db6 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -2489,10 +2489,33 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
 
             assert datasource
 
+            # Check DAR access for datasource
+            dar_allowed = False
+            if is_feature_enabled("DATA_ACCESS_RULES") and hasattr(
+                datasource, "database"
+            ):
+                from superset.data_access_rules.utils import (
+                    AccessCheckResult,
+                    check_table_access,
+                )
+                from superset.sql.parse import Table
+
+                dar_table = Table(
+                    table=datasource.table_name,
+                    schema=datasource.schema,
+                    catalog=getattr(datasource, "catalog", None),
+                )
+                dar_access_info = check_table_access(
+                    database_name=datasource.database.database_name,
+                    table=dar_table,
+                )
+                dar_allowed = dar_access_info.access == AccessCheckResult.ALLOWED
+
             if not (
                 self.can_access_schema(datasource)
                 or self.can_access("datasource_access", datasource.perm or "")
                 or self.is_owner(datasource)
+                or dar_allowed
                 or (
                     # Grant access to the datasource only if dashboard RBAC is enabled
                     # or the user is an embedded guest user with access to the dashboard
diff --git a/superset/utils/filters.py b/superset/utils/filters.py
index 8c4a079949..fb90dc7c7d 100644
--- a/superset/utils/filters.py
+++ b/superset/utils/filters.py
@@ -17,10 +17,51 @@
 from typing import Any
 
 from flask_appbuilder import Model
-from sqlalchemy import or_
+from sqlalchemy import and_, or_
 from sqlalchemy.sql.elements import BooleanClauseList
 
 
+def get_dar_dataset_filters(base_model: type[Model]) -> list[Any]:
+    """Get SQLAlchemy filters for DAR-allowed tables."""
+    # pylint: disable=import-outside-toplevel
+    import logging
+
+    from superset import is_feature_enabled
+    from superset.connectors.sqla.models import Database
+
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return []
+
+    try:
+        from superset.data_access_rules.utils import get_all_allowed_tables
+
+        allowed_tables = get_all_allowed_tables()
+        if not allowed_tables:
+            return []
+
+        # Build OR filters for each allowed table
+        table_filters = []
+        for table in allowed_tables:
+            table_filter = and_(
+                Database.database_name == table.database,
+                base_model.table_name == table.table,
+            )
+            # Add schema filter if specified
+            if table.schema:
+                table_filter = and_(
+                    table_filter,
+                    base_model.schema == table.schema,
+                )
+            table_filters.append(table_filter)
+
+        return table_filters
+    except Exception as ex:
+        logging.getLogger(__name__).warning(
+            "Error getting DAR dataset filters: %s", ex
+        )
+        return []
+
+
 def get_dataset_access_filters(
     base_model: type[Model],
     *args: Any,
@@ -34,10 +75,14 @@ def get_dataset_access_filters(
     schema_perms = security_manager.user_view_menu_names("schema_access")
     catalog_perms = security_manager.user_view_menu_names("catalog_access")
 
+    # Get DAR-based table filters
+    dar_filters = get_dar_dataset_filters(base_model)
+
     return or_(
         Database.id.in_(database_ids),
         base_model.perm.in_(perms),
         base_model.catalog_perm.in_(catalog_perms),
         base_model.schema_perm.in_(schema_perms),
+        *dar_filters,
         *args,
     )


(superset) 01/03: Testing

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch new-dar
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 355432510471e85051960a71af653fabecb2512f
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Dec 17 16:19:42 2025 -0500

    Testing
---
 superset/data_access_rules/api.py     |  75 ++++++++++++++++++-
 superset/data_access_rules/schemas.py |  13 +++-
 superset/data_access_rules/utils.py   | 135 ++++++++++++++++++++++++++++++++++
 superset/databases/filters.py         |  18 ++++-
 superset/security/manager.py          |  45 ++++++++++++
 5 files changed, 282 insertions(+), 4 deletions(-)

diff --git a/superset/data_access_rules/api.py b/superset/data_access_rules/api.py
index f87932378a..c7c9e27f5b 100644
--- a/superset/data_access_rules/api.py
+++ b/superset/data_access_rules/api.py
@@ -23,9 +23,10 @@ including CRUD operations and a group_keys discovery endpoint.
 
 import logging
 
-from flask import Response
+from flask import request, Response
 from flask_appbuilder.api import expose, protect, safe
 from flask_appbuilder.models.sqla.interface import SQLAInterface
+from marshmallow import ValidationError
 
 from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
 from superset.data_access_rules.models import DataAccessRule
@@ -39,6 +40,7 @@ from superset.data_access_rules.utils import get_all_group_keys
 from superset.extensions import event_logger
 from superset.views.base_api import (
     BaseSupersetModelRestApi,
+    requires_json,
     statsd_metrics,
 )
 from superset.views.filters import BaseFilterRelatedRoles, BaseFilterRelatedUsers
@@ -118,6 +120,77 @@ class DataAccessRulesRestApi(BaseSupersetModelRestApi):
         "delete": {"delete": {"summary": "Delete a data access rule"}},
     }
 
+    @expose("/<int:pk>", methods=("PUT",))
+    @protect()
+    @safe
+    @statsd_metrics
+    @requires_json
+    @event_logger.log_this_with_context(
+        action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.put",
+        log_to_statsd=False,
+    )
+    def put(self, pk: int) -> Response:
+        """Update a data access rule.
+        ---
+        put:
+          summary: Update a data access rule
+          parameters:
+          - in: path
+            schema:
+              type: integer
+            name: pk
+            description: The rule pk
+          requestBody:
+            description: Data access rule schema
+            required: true
+            content:
+              application/json:
+                schema:
+                  $ref: '#/components/schemas/DataAccessRulePutSchema'
+          responses:
+            200:
+              description: Rule updated
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      id:
+                        type: number
+                      result:
+                        $ref: '#/components/schemas/DataAccessRulePutSchema'
+            400:
+              $ref: '#/components/responses/400'
+            401:
+              $ref: '#/components/responses/401'
+            404:
+              $ref: '#/components/responses/404'
+            422:
+              $ref: '#/components/responses/422'
+            500:
+              $ref: '#/components/responses/500'
+        """
+        try:
+            item = self.edit_model_schema.load(request.json)
+        except ValidationError as error:
+            return self.response_400(message=error.messages)
+
+        # Get existing rule
+        existing = self.datamodel.get(pk)
+        if not existing:
+            return self.response_404()
+
+        # Update fields
+        for key, value in item.items():
+            setattr(existing, key, value)
+
+        try:
+            self.datamodel.edit(existing)
+            return self.response(200, id=existing.id, result=item)
+        except Exception as ex:
+            logger.error("Error updating data access rule: %s", str(ex), exc_info=True)
+            return self.response_422(message=str(ex))
+
     @expose("/group_keys/", methods=("GET",))
     @protect()
     @safe
diff --git a/superset/data_access_rules/schemas.py b/superset/data_access_rules/schemas.py
index 8a87bde8c5..a1f7f1137a 100644
--- a/superset/data_access_rules/schemas.py
+++ b/superset/data_access_rules/schemas.py
@@ -18,9 +18,10 @@
 Data Access Rules schemas for API serialization/deserialization.
 """
 
-from marshmallow import fields, Schema, validates_schema, ValidationError
+from marshmallow import fields, post_load, Schema, validates_schema, ValidationError
 
 from superset.dashboards.schemas import UserSchema
+from superset.data_access_rules.models import DataAccessRule
 
 # Field descriptions for OpenAPI documentation
 rule_description = """
@@ -68,9 +69,12 @@ class DataAccessRuleListSchema(Schema):
     role_id = fields.Integer(metadata={"description": "ID of the associated role"})
     role = fields.Nested(RoleSchema)
     rule = fields.String(metadata={"description": rule_description})
-    changed_on_delta_humanized = fields.String()
+    changed_on_delta_humanized = fields.Method("get_changed_on_delta_humanized")
     changed_by = fields.Nested(UserSchema(exclude=["username"]))
 
+    def get_changed_on_delta_humanized(self, obj: DataAccessRule) -> str:
+        return obj.changed_on_delta_humanized()
+
 
 class DataAccessRuleShowSchema(Schema):
     """Schema for showing a single data access rule."""
@@ -146,6 +150,11 @@ class DataAccessRulePostSchema(Schema):
             except json.JSONDecodeError as ex:
                 raise ValidationError(f"Invalid JSON: {ex}", field_name="rule") from ex
 
+    @post_load
+    def make_object(self, data: dict, **kwargs: dict) -> DataAccessRule:
+        """Convert validated data to a DataAccessRule instance."""
+        return DataAccessRule(**data)
+
 
 class DataAccessRulePutSchema(Schema):
     """Schema for updating a data access rule."""
diff --git a/superset/data_access_rules/utils.py b/superset/data_access_rules/utils.py
index 7ad55b6eff..31689c8b4f 100644
--- a/superset/data_access_rules/utils.py
+++ b/superset/data_access_rules/utils.py
@@ -560,6 +560,141 @@ def apply_data_access_rules(
         parsed_statement.apply_cls(cls_rules)
 
 
+def get_allowed_tables(
+    database_name: str,
+    schema: str | None = None,
+    catalog: str | None = None,
+) -> tuple[set[str], bool]:
+    """
+    Get all table names that the current user has access to via Data Access Rules
+    for a specific database and schema.
+
+    Args:
+        database_name: The database name to check
+        schema: Optional schema name to filter by
+        catalog: Optional catalog name to filter by
+
+    Returns:
+        Tuple of (set of table names, bool indicating if schema-level access is granted).
+        If schema-level access is granted, the set may be empty but all tables are allowed.
+    """
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return set(), False
+
+    rules = get_user_rules()
+    if not rules:
+        return set(), False
+
+    table_names: set[str] = set()
+    schema_level_access = False
+
+    for rule in rules:
+        rule_dict = rule.rule_dict
+
+        # Collect tables from allowed entries
+        for entry in rule_dict.get("allowed", []):
+            if entry.get("database") != database_name:
+                continue
+
+            # If catalog is specified in the entry, it must match
+            entry_catalog = entry.get("catalog")
+            if catalog is not None and entry_catalog is not None:
+                if entry_catalog != catalog:
+                    continue
+
+            # If schema is specified, check if it matches
+            entry_schema = entry.get("schema")
+            if schema is not None and entry_schema is not None:
+                if entry_schema != schema:
+                    continue
+
+            # If entry has a table, add it to the set
+            if table := entry.get("table"):
+                table_names.add(table)
+            elif entry_schema == schema or (entry_schema is None and schema is None):
+                # Schema-level or database-level access without table means all tables
+                schema_level_access = True
+
+    return table_names, schema_level_access
+
+
+def get_allowed_schemas(database_name: str, catalog: str | None = None) -> set[str]:
+    """
+    Get all schema names that the current user has access to via Data Access Rules
+    for a specific database.
+
+    Args:
+        database_name: The database name to check
+        catalog: Optional catalog name to filter by
+
+    Returns:
+        Set of schema names the user has access to.
+    """
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return set()
+
+    rules = get_user_rules()
+    if not rules:
+        return set()
+
+    schema_names: set[str] = set()
+
+    for rule in rules:
+        rule_dict = rule.rule_dict
+
+        # Collect schemas from allowed entries
+        for entry in rule_dict.get("allowed", []):
+            if entry.get("database") != database_name:
+                continue
+
+            # If catalog is specified in the entry, it must match
+            entry_catalog = entry.get("catalog")
+            if catalog is not None and entry_catalog is not None:
+                if entry_catalog != catalog:
+                    continue
+
+            # If the entry grants database-level access (no schema specified),
+            # we return an empty set to indicate "all schemas" should be allowed
+            # This will be handled by the caller
+            if schema := entry.get("schema"):
+                schema_names.add(schema)
+            elif entry.get("database") == database_name:
+                # Database-level access without schema means all schemas
+                # Return a special marker that caller can check
+                schema_names.add("*")
+
+    return schema_names
+
+
+def get_allowed_databases() -> set[str]:
+    """
+    Get all database names that the current user has access to via Data Access Rules.
+
+    This function is used to populate database selectors in SQL Lab and elsewhere.
+
+    Returns:
+        Set of database names the user has access to.
+    """
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return set()
+
+    rules = get_user_rules()
+    if not rules:
+        return set()
+
+    database_names: set[str] = set()
+
+    for rule in rules:
+        rule_dict = rule.rule_dict
+
+        # Collect databases from allowed entries
+        for entry in rule_dict.get("allowed", []):
+            if database := entry.get("database"):
+                database_names.add(database)
+
+    return database_names
+
+
 def get_all_group_keys(
     database_name: str | None = None,
     table: Table | None = None,
diff --git a/superset/databases/filters.py b/superset/databases/filters.py
index 321eb62100..4f0920319e 100644
--- a/superset/databases/filters.py
+++ b/superset/databases/filters.py
@@ -23,11 +23,22 @@ from sqlalchemy.orm import Query
 from sqlalchemy.sql.expression import cast
 from sqlalchemy.sql.sqltypes import JSON
 
-from superset import security_manager
+from superset import is_feature_enabled, security_manager
 from superset.models.core import Database
 from superset.views.base import BaseFilter
 
 
+def get_dar_allowed_databases() -> set[str]:
+    """Get databases allowed by Data Access Rules for the current user."""
+    if not is_feature_enabled("DATA_ACCESS_RULES"):
+        return set()
+
+    # Lazy import to avoid circular dependency
+    from superset.data_access_rules.utils import get_allowed_databases
+
+    return get_allowed_databases()
+
+
 def can_access_databases(view_menu_name: str) -> set[str]:
     """
     Return names of databases available in `view_menu_name`.
@@ -62,10 +73,15 @@ class DatabaseFilter(BaseFilter):  # pylint: disable=too-few-public-methods
         catalog_access_databases = can_access_databases("catalog_access")
         schema_access_databases = can_access_databases("schema_access")
         datasource_access_databases = can_access_databases("datasource_access")
+
+        # Include databases from Data Access Rules
+        dar_databases = get_dar_allowed_databases()
+
         database_names = sorted(
             catalog_access_databases
             | schema_access_databases
             | datasource_access_databases
+            | dar_databases
         )
 
         return query.filter(
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 8490c049e3..f377832194 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -976,6 +976,19 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                 }
             )
 
+        # Data Access Rules
+        # pylint: disable=import-outside-toplevel
+        from superset import is_feature_enabled
+
+        if is_feature_enabled("DATA_ACCESS_RULES"):
+            from superset.data_access_rules.utils import get_allowed_schemas
+
+            dar_schemas = get_allowed_schemas(database.database_name, catalog)
+            if "*" in dar_schemas:
+                # Database-level access means all schemas
+                return schemas
+            accessible_schemas.update(dar_schemas)
+
         return schemas & accessible_schemas
 
     def get_catalogs_accessible_by_user(
@@ -1091,6 +1104,24 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
             )
         }
 
+        # Check Data Access Rules
+        # pylint: disable=import-outside-toplevel
+        from superset import is_feature_enabled
+
+        if is_feature_enabled("DATA_ACCESS_RULES"):
+            from superset.data_access_rules.utils import get_allowed_tables
+
+            dar_tables, schema_level_access = get_allowed_tables(
+                database.database_name, schema, catalog
+            )
+            if schema_level_access:
+                # Schema-level access means all tables in the schema
+                return datasource_names
+
+            # Add DAR tables to accessible datasources
+            for table_name in dar_tables:
+                user_datasources.add(DatasourceName(table_name, schema, catalog))
+
         return [
             datasource
             for datasource in datasource_names
@@ -2410,6 +2441,20 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                         # access to any datasource is sufficient
                         break
                 else:
+                    # Check Data Access Rules before denying
+                    if is_feature_enabled("DATA_ACCESS_RULES"):
+                        from superset.data_access_rules.utils import (
+                            AccessCheckResult,
+                            check_table_access,
+                        )
+
+                        access_info = check_table_access(
+                            database_name=database.database_name,
+                            table=table_,
+                        )
+                        if access_info.access == AccessCheckResult.ALLOWED:
+                            continue
+
                     denied.add(table_)
 
             if denied:


(superset) 02/03: RLS and CLS working

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch new-dar
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 2e7df4614c8ccc7dbcd3c57888f3ea8f5769c585
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Dec 17 17:08:58 2025 -0500

    RLS and CLS working
---
 superset/data_access_rules/api.py   |  4 ++--
 superset/data_access_rules/utils.py | 47 +++++++++++++++++++++++++++++++++----
 superset/sql/parse.py               |  3 +++
 3 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/superset/data_access_rules/api.py b/superset/data_access_rules/api.py
index c7c9e27f5b..fcd54474fb 100644
--- a/superset/data_access_rules/api.py
+++ b/superset/data_access_rules/api.py
@@ -31,7 +31,6 @@ from marshmallow import ValidationError
 from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
 from superset.data_access_rules.models import DataAccessRule
 from superset.data_access_rules.schemas import (
-    DataAccessRuleListSchema,
     DataAccessRulePostSchema,
     DataAccessRulePutSchema,
     DataAccessRuleShowSchema,
@@ -109,7 +108,8 @@ class DataAccessRulesRestApi(BaseSupersetModelRestApi):
 
     add_model_schema = DataAccessRulePostSchema()
     edit_model_schema = DataAccessRulePutSchema()
-    list_model_schema = DataAccessRuleListSchema()
+    # Don't use custom list_model_schema - let Flask-AppBuilder handle
+    # nested relationships via list_columns dot notation
     show_model_schema = DataAccessRuleShowSchema()
 
     openapi_spec_methods = {
diff --git a/superset/data_access_rules/utils.py b/superset/data_access_rules/utils.py
index 31689c8b4f..90582b7291 100644
--- a/superset/data_access_rules/utils.py
+++ b/superset/data_access_rules/utils.py
@@ -551,14 +551,51 @@ def apply_data_access_rules(
         if table_cls:
             cls_rules[qualified_table] = table_cls
 
-    # Apply RLS if we have predicates
+    # Apply CLS first (before RLS) so that hidden columns are removed
+    # before RLS wraps the query in a subquery
+    if cls_rules:
+        # Build schema dict for sqlglot's qualify() to expand SELECT *
+        # sqlglot expects nested format: {catalog: {schema: {table: {col: type}}}}
+        # or {schema: {table: {col: type}}} without catalog
+        table_schemas: dict[str, Any] = {}
+        for table in cls_rules.keys():
+            try:
+                columns = database.get_columns(table)
+                col_types = {
+                    col["column_name"]: str(col.get("type", "VARCHAR"))
+                    for col in columns
+                }
+
+                # Build nested structure for sqlglot
+                if table.catalog:
+                    if table.catalog not in table_schemas:
+                        table_schemas[table.catalog] = {}
+                    if table.schema:
+                        if table.schema not in table_schemas[table.catalog]:
+                            table_schemas[table.catalog][table.schema] = {}
+                        table_schemas[table.catalog][table.schema][table.table] = col_types
+                    else:
+                        table_schemas[table.catalog][table.table] = col_types
+                elif table.schema:
+                    if table.schema not in table_schemas:
+                        table_schemas[table.schema] = {}
+                    table_schemas[table.schema][table.table] = col_types
+                else:
+                    table_schemas[table.table] = col_types
+            except Exception as ex:
+                logger.warning(
+                    "Could not fetch schema for table %s: %s",
+                    table,
+                    ex,
+                )
+
+        parsed_statement.apply_cls(cls_rules, schema=table_schemas if table_schemas else None)
+
+    # Apply RLS after CLS - RLS wraps the query in a subquery with SELECT *
+    # which will pick up the already-transformed columns from CLS
     if rls_predicates:
         parsed_statement.apply_rls(catalog, schema, rls_predicates, method)
 
-    # Apply CLS if we have rules
-    if cls_rules:
-        parsed_statement.apply_cls(cls_rules)
-
 
 def get_allowed_tables(
     database_name: str,
diff --git a/superset/sql/parse.py b/superset/sql/parse.py
index 3d4f55010b..c674342820 100644
--- a/superset/sql/parse.py
+++ b/superset/sql/parse.py
@@ -1536,11 +1536,14 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
         # Without schema: qualifies single-table queries, partial for JOINs.
         from sqlglot.optimizer.qualify import qualify
 
+        # Only expand stars if schema is provided (from DAR with feature flag enabled)
+        # to avoid potential errors in other contexts
         self._parsed = qualify(
             self._parsed,
             schema=schema,
             dialect=self._dialect,
             validate_qualify_columns=False,
+            expand_stars=bool(schema),
         )
 
         transformer = CLSTransformer(rules, self._dialect)