Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions superset/mcp_service/utils/permissions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def get_allowed_fields(
if not user:
user = get_current_user()

# Get sensitive fields for this object type
sensitive_fields = SENSITIVE_FIELDS.get(object_type, set())
sensitive_fields.update(SENSITIVE_FIELDS.get("common", set()))
base=SENSITIVE_FIELDS.get(object_type, set())
common=SENSITIVE_FIELDS.get("common", set())
sensitive_fields= set(base)|set(common)
Comment on lines +145 to +147
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant Set Conversion category Design

Tell me more
What is the issue?

The code unnecessarily converts base and common to sets twice when they are already sets from SENSITIVE_FIELDS dictionary.

Why this matters

This creates unnecessary set conversions that impact performance and code clarity without adding any value.

Suggested change ∙ Feature Preview
base = SENSITIVE_FIELDS.get(object_type, set())
common = SENSITIVE_FIELDS.get("common", set())
sensitive_fields = base | common  # Set union operator directly on sets
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your disappointment. Let's focus on improving the code. Would you like to discuss the suggested change or explore alternative solutions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes do that

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Let's consider these alternatives:

  1. Use set union directly:

    sensitive_fields = SENSITIVE_FIELDS.get(object_type, set()) | SENSITIVE_FIELDS.get("common", set())
  2. Use dict.get() with default empty set:

    sensitive_fields = SENSITIVE_FIELDS.get(object_type, set()) | SENSITIVE_FIELDS.get("common", set())
  3. Use dict.setdefault() to ensure sets:

    base = SENSITIVE_FIELDS.setdefault(object_type, set())
    common = SENSITIVE_FIELDS.setdefault("common", set())
    sensitive_fields = base | common

Which approach do you prefer, or do you have another idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask for a review

Comment on lines +145 to +147
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around assignment operators. Python PEP 8 requires spaces around assignment operators. Change base= to base = , common= to common = , and sensitive_fields= to sensitive_fields = .

Suggested change
base=SENSITIVE_FIELDS.get(object_type, set())
common=SENSITIVE_FIELDS.get("common", set())
sensitive_fields= set(base)|set(common)
base = SENSITIVE_FIELDS.get(object_type, set())
common = SENSITIVE_FIELDS.get("common", set())
sensitive_fields = set(base) | set(common)

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant set conversions. The .get(object_type, set()) calls already return sets, so wrapping them with set() again is unnecessary. Since base and common are already sets, use sensitive_fields = base | common directly.

Suggested change
sensitive_fields= set(base)|set(common)
sensitive_fields = base | common

Copilot uses AI. Check for mistakes.

# If no user, only allow non-sensitive fields
if not user:
Expand Down
Loading