Skip to content
Francesco Castaldi
← Blog

Tech

Production Open Source Fixes: Lessons from Superset and Trino

Deep dive into production-grade pull requests across Apache Superset, Trino, and Mattermost: resolving CBO stats loss, API crashes, and dependency risks.

Francesco Castaldi9 min read

Modern developer workstation overlooking high-performance server racks with glowing amber and cyan data telemetry lines

Contributing to tier-1 open source platforms like Apache Superset, Trino, and Mattermost is fundamentally different from internal application development. In foundations serving tens of thousands of organizations, code changes operate under strict scrutiny.

Every pull request must maintain backward compatibility, preserve performance guarantees across massive datasets, and withstand multi-maintainer review rounds. A single misplaced translation macro can fail a release pipeline; an unnoticed snapshot expiration can degrade query planner performance across a petabyte-scale data lake.

Navigating recent review threads and maintainer feedback across these ecosystems highlighted practical engineering patterns worth documenting. Here is an architectural breakdown of what failed, how we solved it, and what it teaches us about building resilient systems.

Preserving Iceberg NDV statistics in Trino query planning

Distributed query engines such as Trino rely on accurate cost-based optimization (CBO) to generate efficient execution plans. When joining multi-million-row tables, the planner examines column-level Number of Distinct Values (NDV) to choose between broadcast joins and distributed hash partitions.

In Apache Iceberg, column statistics are stored in serialized Puffin metric files bound to individual table snapshots. When executing row-level mutations (such as MERGE, UPDATE, or DELETE), the engine creates a new snapshot representing the modified state.

Initial Snapshot (S1) ──► Puffin Stats File (NDV for all columns)
       │
       ▼ [Row-level MERGE creates S2]
New Snapshot (S2)     ──► No new stats file written (inherits S1 pointer)
       │
       ▼ [expire_snapshots purges S1]
Snapshot S2 remaining ──► S1 stats file purged! Permanent NDV loss

Snapshot expiration and cost-based optimization risk

The underlying issue surfaced during table maintenance:

  1. Row-level writes in Iceberg did not generate fresh statistics files to minimize write amplification.
  2. Trino temporarily resolved column statistics by traversing backwards through prior snapshot history.
  3. Once maintenance procedures executed expire_snapshots, older metadata files were deleted from object storage.
  4. With historical snapshots removed, NDV estimates permanently disappeared until a costly manual ANALYZE was triggered.

[!IMPORTANT] When NDV statistics vanish, Trino's CBO falls back to default heuristics. This frequently flips optimal broadcast joins into distributed partition exchanges, causing severe network shuffle skew and memory exhaustion on worker nodes.

Zero-overhead metadata carry-forward

In PR #31546, the solution registers the existing GenericStatisticsFile directly onto the currentSnapshotId during write finalization, mirroring how OPTIMIZE commands handle metadata retention.

During the review exchange with maintainers @raunaqmorarka and @findinpath, the critical challenge was ensuring that metadata retention incurred zero extra file I/O overhead. We confirmed this via a dedicated unit test in TestIcebergFileOperations:

@Test
public void testExpireSnapshotsDoesNotReadOrWriteStatisticsFiles()
{
    // Verifies snapshot expiration re-points existing metadata
    // without triggering redundant storage read/write cycles.
    assertFileSystemAccesses(
        "ALTER TABLE test_retention EXECUTE expire_snapshots",
        ImmutableMultiset.of()
    );
}

By verifying zero storage touches during snapshot pruning, we preserved critical query planner estimates without penalizing commit latency.

Clean API failure boundaries: Superset temporal filters

In analytical dashboards, date and time filtering is the single most exercised query path. Users frequently test relative date math, such as Last 7 days or custom expressions with negative shifts.

In Apache Superset, malformed temporal expressions or inverted relative time-shifts previously bubbled up unhandled exceptions from deep within superset/models/helpers.py. The resulting user experience was poor: the entire Explore view crashed with an opaque HTTP 500 Internal Server Error.

Client Request ──► [Malformed Time Range: "2026-13-45 : now"]
                         │
                         ▼
             superset/models/helpers.py
                         │  (Unhandled parsing failure)
                         ▼
             HTTP 500 Internal Server Error (Broken UI)

Traceback preservation and Babel translation drift

The goal of PR #45822 was converting these unhandled crashes into descriptive HTTP 400 Bad Request responses with actionable error payloads. However, the review cycle with committer @sadpandajoe revealed two critical production nuances:

  1. Translation Pot Drift: Wrapping internal helper exceptions with Flask-Babel's gettext wrapper _() altered the translation catalog extraction schema. This broke Superset's strict babel-extract CI check. Low-level exception helpers should pass raw, standardized error keys rather than localized UI strings.
  2. Exception Chaining: Python's exception stack must preserve root causation. Swallowing the underlying datetime parsing error obscured debugging traces. Using explicit chaining (raise QueryObjectValidationError(...) from ex) kept the traceback intact in backend log aggregators while returning clean HTTP 400 status codes to the client.

[!TIP] Never introduce internationalization helpers _() inside low-level data layer models. Translation belongs at the presentation boundary; core analytical engines must raise stable, machine-readable exception contracts.

Furthermore, we expanded unit test suites covering DATE_RANGE_TIMESHIFTS_ENABLED with inverted offsets, verifying that relative offset rewrites handle boundary conditions safely before hitting the database dialect compiler.

Vulnerability remediation without dependency disruption

Modern container scanning tools like Trivy continuously flag Common Vulnerabilities and Exposures (CVEs) across Python monorepos. In PR #45186, our objective was resolving Trivy security alerts across cryptography, msgpack, and pyarrow.

In an enterprise framework, security upgrades cannot be performed through naive version bumps. Overly aggressive pinning causes dependency resolver conflicts with downstream plugins and orchestrators.

Upstream CVE Alert (Trivy)
       │
       ▼
Reachability Analysis ──► Is vulnerable code path invoked by Superset?
       │
       ├──► No: Document mitigated risk in UPDATING.md
       └──► Yes: Widen lower version floor without capping major upper bounds

Reachability analysis and version floor relaxation

During review iterations with @hainenber and @sadpandajoe, we established three governing rules:

  • Construct an Explicit Reachability Matrix: For each reported CVE, analyze whether Superset's call paths actually reach the vulnerable C-extensions or protocol parsers.
  • Widen Version Ranges Rather Than Hard Pinning: Instead of pinning an exact point release, widen the allowed constraint range (cryptography >= 42.0.8, < 45.0.0) so downstream distributions retain flexibility.
  • Purge Obsolete Fallback Logic: While adjusting cryptographic certificate parsing, we eliminated legacy retry fallback loops in load_pem_x509_certificate, replacing defensive workarounds with modern, standardized cryptography APIs.

All changes were thoroughly documented in UPDATING.md, providing operators with clear migration instructions.

UI state deduplication in virtualized selects

On the frontend, Superset relies on custom React form controls to manage dashboard filters and SQL parameters. In PR #44894, we addressed race conditions in Select and AsyncSelect components that caused duplicate options to appear when users created custom tags while scrolling through paginated datasets.

Label-only deduplication in recycled DOM lists

Working through review comments from @aminghadersohi surfaced subtle architectural requirements:

  1. Decoupling Comparison from Synthetic IDs: When options are streamed asynchronously, newly typed options receive temporary synthetic identifiers. Comparing options by identity caused false mismatches. Restricting isRedundantNewOption comparisons strictly to normalized label values eliminated duplicate badges entirely.
  2. Strict Boolean Typing: Ensuring isNewOption evaluates to a strict boolean primitive (boolean) rather than truthy/falsy unions prevented unwanted re-renders in virtualized lists.
  3. Synthetic Event Dispatch in Virtual Lists: Unit tests for virtualized dropdowns often pass deceptively because mocked DOM containers fail to simulate container scroll heights. We implemented integration tests that dispatch synthetic scroll events to trigger item recycling:
// Simulating virtual list scroll event to verify option deduplication
const virtualList = screen.getByRole("listbox");
fireEvent.scroll(virtualList, { target: { scrollTop: 450 } });
 
expect(screen.getAllByText("Custom Metric")).toHaveLength(1);

[!NOTE] Testing virtualized components requires verifying DOM reconciliation after scroll offsets. Asserting element existence without triggering container scroll leaves threshold recycling bugs completely undetected.

Dialect metadata and AST linting across database engine specs

In Apache Superset, database engine specifications define connection parameters, SQL dialect capabilities, and UI configuration fields for dozens of enterprise data sources. In PR #43695, we resolved metadata gaps and AST scanning crashes across multiple database dialects.

Analytical platforms frequently rely on specialized drivers such as Databricks and ClickHouse Connect. In older releases, incomplete dialect metadata caused runtime inspection warnings and broken documentation hyperlinks.

Specification alignment and connection safety

Working through 10 review threads with committers and automated quality bots, we resolved several dialect-specific issues:

  • SQLAlchemy 2.0 Dialect Alignment: Standardized DatabricksNativeEngineSpec, DatabricksODBCEngineSpec, and DatabricksHiveEngineSpec to comply with SQLAlchemy 2.0 dialect contracts.
  • Explicit Documentation Linking: Added an explicit sqlalchemy_docs_url for ClickHouse Connect, preventing fallback routing to generic or nonexistent documentation pages.
  • Dialect Parameter Hardening: Added the IBM i RDB name parameter, confirmed Aurora PostgreSQL's default port (5432), and standardized the Parseable scheme (parseable+http://).

AST scanner isolation in automated linters

The most challenging review aspect involved lint_metadata.py, Superset's AST-based linter that validates engine specification completeness across the repository.

# AST visitor traversing class attribute annotations safely
def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
    # Handle bare annotations without default values
    if node.value is None and isinstance(node.target, ast.Name):
        self.documented_attributes.add(node.target.id)
    self.generic_visit(node)

The linter previously crashed on Python 3.10+ bare type annotations lacking default assignments. Furthermore, unit tests for the AST linter wrote test files directly into the repository tree, causing race conditions in parallel CI runners. We rewrote the test harness to run inside isolated pytest tmp_path fixtures, guaranteeing zero test pollution and deterministic CI execution.

User-centric time formatting in Mattermost Calendar

Distributed teams collaborate across different continents and cultural conventions. In the Mattermost Microsoft Calendar plugin (written in Go), calendar notifications and daily event digests originally hardcoded 12-hour timestamps without spacing (6:00PM).

Centralizing locale formatting in Go workers

In PR #553, we centralized time formatting into a shared TimeFormatForUser utility. Rather than scattering timezone logic across independent notification workers, the utility inspects the user's explicit preference:

// TimeFormatForUser resolves the canonical layout string
func TimeFormatForUser(use24Hour bool) string {
    if use24Hour {
        return "15:04"
    }
    return "3:04 PM"
}

Alongside formatting adjustments, PR #554 introduced comprehensive unit test suites covering the OAuth token refresh lifecycle and stored credential synchronization under concurrent session requests. Both pull requests achieved full maintainer approval (@avasconcelos114) and 100% green CI validation across Snyk security scans and CLA verifications.

Engineering summary & architectural comparison

Maintaining quality across open source projects requires deep alignment between code structure, automated verification, and maintainer consensus.

Project Pull Request Subsystem Failure Mode / Problem Architectural Resolution Verification Strategy
Trino #31546 Iceberg Connector NDV statistics lost after row-level writes upon snapshot expiry Retain GenericStatisticsFile on currentSnapshotId with zero I/O testExpireSnapshotsDoesNotReadOrWriteStatisticsFiles
Apache Superset #45822 Temporal Filters Malformed time ranges surfaced unhandled HTTP 500 errors Return clean HTTP 400 with from ex and no translation pot drift Relative-offset and inverted timeshift test suite
Apache Superset #45186 Security Constraints Trivy CVE alerts across cryptography, msgpack, and pyarrow Granular reachability matrix, UPDATING.md doc, clean X.509 loader Trivy vulnerability scan and dependency resolver CI
Apache Superset #44894 UI Select Controls Duplicate badges and synthetic ID collisions on scroll Label-only redundancy check, boolean typing, virtual list tests Virtual list synthetic scroll event tests
Apache Superset #43695 Database Engine Specs Missing dialect metadata and AST scanner crashes on bare annotations SQLAlchemy 2.0 spec alignment, explicit doc URLs, AST lint isolation AST scanner test suite with pytest tmp_path fixtures
Mattermost #553 MS Calendar Plugin Time display ignored user 12h/24h international preferences Centralized TimeFormatForUser single source of truth (Approved) Unit tests across user locale preference matrix
Mattermost #554 OAuth Token Store Regressions during concurrent token refresh and store lifecycle Comprehensive test harness for OAuth token refresh (Approved) Concurrency and store mock lifecycle tests

Table 1: Comparative breakdown of recent upstream pull requests, failure modes, and architectural resolutions.

[!WARNING] In large open source codebases, shipping the fix is only half the battle. Explaining architectural trade-offs clearly in review threads, providing reproducible test cases, and respecting repository conventions is what turns a proposed PR into merged production code.

Every resolved comment from maintainers reinforces an essential lesson: software reliability is built on small, disciplined decisions, from handling exceptions without breaking translation catalogs to preserving query statistics without redundant disk writes.

  • #open-source
  • #apache-superset
  • #trino
  • #code-review
  • #data-engineering

Share article

Zero tracking, no cookies, privacy-respecting.

Share article

Article

Production Open Source Fixes: Lessons from Superset and Trino

https://francescocastaldi.it/blog/production-open-source-fixes-lessons-from-superset-and-trino