pola-rs/polars · error

invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT

Error message

invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT: {x}

What it means

Polars reads the environment variable POLARS_INFLIGHT_SINK_MORSEL_LIMIT to override how many morsels may be in flight per sink pipeline. If the variable is set but cannot be parsed as a non-zero usize, the library panics immediately rather than silently ignoring the bad value.

Solutions

  1. Set POLARS_INFLIGHT_SINK_MORSEL_LIMIT to a positive integer, e.g. export POLARS_INFLIGHT_SINK_MORSEL_LIMIT=64.
  2. Unset the variable entirely (unset POLARS_INFLIGHT_SINK_MORSEL_LIMIT) to use the computed default.
  3. Check for empty string or whitespace values in your environment (empty string still fails parse).

Example fix

# before
export POLARS_INFLIGHT_SINK_MORSEL_LIMIT=0
# after
export POLARS_INFLIGHT_SINK_MORSEL_LIMIT=64
Defensive patterns

Strategy: validation

Validate before calling

import os
v = os.environ.get("POLARS_INFLIGHT_SINK_MORSEL_LIMIT")
if v is not None:
    assert v.isdigit() and int(v) > 0, f"POLARS_INFLIGHT_SINK_MORSEL_LIMIT must be a positive integer, got {v!r}"

Type guard

def is_positive_int(s: str) -> bool:
    return s.isdigit() and int(s) > 0

Try / catch

// Rust side cannot catch panic; validate env before calling polars:
let v = std::env::var("POLARS_INFLIGHT_SINK_MORSEL_LIMIT").unwrap_or_default();
assert!(v.is_empty() || v.parse::<usize>().map_or(false, |n| n > 0));

Prevention

When it happens

Trigger: Setting POLARS_INFLIGHT_SINK_MORSEL_LIMIT to anything not a positive integer (e.g. '0', 'abc', '10.5', empty string) and then running a streaming query with a sink (sink_parquet/csv etc.), which calls inflight_morsel_limit via num_pipelines_per_sink or sink pipeline startup.

Common situations: Hand-edited shell profiles or CI/exported env tuning knobs with typos; copy-pasted values with units ('100m', '5k'); setting '0' which NonZeroUsize rejects.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/e97708ae530a5ec5. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-stream/src/nodes/io_sinks/config.rs:33

const DEFAULT_PARTITIONED_UPLOAD_CHUNK_SIZE: NonZeroUsize =
    NonZeroUsize::new(6 * 1024 * 1024).unwrap();

pub struct IOSinkNodeConfig {
    pub file_format: FileWriteFormat,
    pub target: IOSinkTarget,
    pub unified_sink_args: UnifiedSinkArgs,
    pub input_schema: SchemaRef,
}

impl IOSinkNodeConfig {
    pub fn num_pipelines_per_sink(&self, num_pipelines: NonZeroUsize) -> NonZeroUsize {
        NonZeroUsize::min(num_pipelines, self.inflight_morsel_limit(num_pipelines))
    }

    pub fn inflight_morsel_limit(&self, num_pipelines: NonZeroUsize) -> NonZeroUsize {
        if let Ok(v) = std::env::var("POLARS_INFLIGHT_SINK_MORSEL_LIMIT").map(|x| {
            x.parse::<NonZeroUsize>().unwrap_or_else(|_| {
                panic!("invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT: {x}")
            })
        }) {
            return v;
        };

        NonZeroUsize::saturating_add(
            num_pipelines,
            // Additional buffer to accommodate head-of-line blocking
            4,
        )
    }

    pub fn max_open_sinks(&self) -> NonZeroUsize {
        if let Ok(v) = std::env::var("POLARS_MAX_OPEN_SINKS").map(|x| {
            x.parse::<NonZeroUsize>()
                .unwrap_or_else(|_| panic!("invalid value for POLARS_MAX_OPEN_SINKS: {x}"))
        }) {
            return v;

View on GitHub (pinned to fe841f959e)