villebro opened a new pull request, #38167:
URL: https://github.com/apache/superset/pull/38167
# SUMMARY
Fixes critical extension loading failures when extension IDs contain hyphens
by refactoring the CLI to use extension ID as the primary source for all
technical identifiers. This change anchors all extension naming on kebab-case
IDs (required for REST API compatibility) and converts to platform-specific
formats. Extensions with hyphenated names (e.g., "chart-builder") were
generating invalid Python package names, causing backend imports to fail
completely.
## Problem & Root Cause
**Critical Bug:**
- Extension ID: `chart-builder` (valid kebab-case)
- Backend package: `chart-builder` (INVALID - Python syntax error)
- Module Federation: `chart-builder` (INVALID - JavaScript identifier error)
- Result: Extension fails to load, backend crashes on import
## Solution: ID-Based Name Conversion
The extensive refactor was necessary because we needed to:
1. **Fix the immediate bug**: Convert hyphenated IDs to valid platform
identifiers
2. **Ensure consistency**: All technical names derive from the same source
(extension ID)
3. **Maintain idioms**: Each platform gets its preferred naming convention
### Why Kebab-Case as Base?
Extension IDs must be URL-compatible for REST API endpoints
(`/api/v1/extensions/chart-builder/`). We use kebab-case as the source for all
technical names (rather than snake_case throughout) because:
- **REST API requirement**: Extension IDs appear directly in URL paths and
must be URL-safe without encoding
- **Web standards alignment**: kebab-case is the web standard for URLs, npm
packages, and CSS selectors
- **Platform idioms**: Each platform gets its preferred format (camelCase
for JS, snake_case for Python) converted from the URL-safe base
- **Future-proof**: Avoids conflicts with web tooling and maintains
consistency with web ecosystem conventions
## Key Changes
### CLI (`superset-extensions-cli/`)
- **utils.py**: Added `kebab_to_camel_case()` and `kebab_to_snake_case()`
functions to convert hyphenated IDs
- **cli.py**: Updated manual `ExtensionNames` construction to use ID-based
generation
- **generate_extension_names()**: Now derives technical names from generated
ID instead of display name
- **Removed**: `name_to_snake_case()` and `name_to_camel_case()` (replaced
by kebab converters)
### Superset Core (`superset/`)
- **extensions/utils.py**: Introduced `superset_extensions` namespace
packages with automatic creation via enhanced `InMemoryFinder`
- **Unrelated but critical fix**: Prevents namespace conflicts when
extension names collide with Python dependencies (e.g., an extension named
"pandas" would conflict with the pandas library)
- New namespaced import system: `superset_extensions.extension_name`
instead of direct imports
- Provides clear extension isolation and eliminates import shadowing issues
### Documentation (`docs/`)
- **quick-start.md**: Updated examples to show ID-based naming flow
- **development.md**: Updated project structure and extension.json examples
## Flow Example
```bash
# CLI prompts
Extension name: "Hello World"
Extension ID [hello-world]: chart-tool
# Generated names (all from ID, platform-safe)
Frontend package: "chart-tool" (valid npm name)
Module Federation: "chartTool" (valid JS identifier)
Backend package: "chart_tool" (valid Python identifier)
Python namespace: "superset_extensions.chart_tool" (importable)
```
## Testing
- All existing tests pass with updated expectations
- Tested locally with a test extension without issues
- Added comprehensive tests for new kebab conversion functions
- Updated template tests to use ID-based approach
- Fixed namespace package loading for backend extensions
- Verified extensions with hyphens now load correctly
**Type**: Bug Fix + Refactor
**Scope**: Extensions CLI + Core Loading
**Breaking**: None (backward compatible)
**Fixes**: Extension loading failures with hyphenated names
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]