pola-rs/polars · error
creating extension types not allowed - try setting the envir
Error message
creating extension types not allowed - try setting the environment variable {env} What it means
Safety gate around Polars' internal extension-type mechanism (create_extension in the object/extension module): registering/creating custom extension types is disabled unless the opt-in environment variable (POLARS_ALLOW_EXTENSION) is set, because creating extension arrays from untrusted input is unsafe.
Source
Thrown at crates/polars-core/src/chunked_array/object/extension/mod.rs:69
(drop_fn)()
}
}
}
// https://stackoverflow.com/questions/28127165/how-to-convert-struct-to-u8d
// not entirely sure if padding bytes in T are initialized or not.
unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
std::slice::from_raw_parts((p as *const T) as *const u8, size_of::<T>())
}
/// Create an extension Array that can be sent to arrow and (once wrapped in [`PolarsExtension`] will
/// also call drop on `T`, when the array is dropped.
pub(crate) fn create_extension<I: Iterator<Item = Option<T>> + TrustedLen, T: Sized + Default>(
iter: I,
) -> PolarsExtension {
let env = "POLARS_ALLOW_EXTENSION";
if !(POLARS_ALLOW_EXTENSION.load() || std::env::var(env).is_ok()) {
panic!("creating extension types not allowed - try setting the environment variable {env}")
}
let t_size = size_of::<T>();
let t_alignment = align_of::<T>();
let n_t_vals = iter.size_hint().1.unwrap();
let mut buf = Vec::with_capacity(n_t_vals * t_size);
let mut validity = BitmapBuilder::with_capacity(n_t_vals);
// when we transmute from &[u8] to T, T must be aligned correctly,
// so we pad with bytes until the alignment matches
let n_padding = (buf.as_ptr() as usize) % t_alignment;
buf.extend(std::iter::repeat_n(0, n_padding));
// transmute T as bytes and copy in buffer
for opt_t in iter.into_iter() {
match opt_t {
Some(t) => {
unsafe {View on GitHub (pinned to 5d8ebabf11)
Solutions
- Set the indicated environment variable (e.g. POLARS_ALLOW_EXTENSION...) to opt in to creating extension/object types.
- Avoid constructing extension types in untrusted/production code; they can carry unsafe invariants.
Defensive patterns
Strategy: validation
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "creating extension types not allowed - try setting the environment variable {env}". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.
Common situations: Encountered when input data or configuration does not meet the preconditions of the throwing code path ("creating extension types not allowed - try setting the environment variable {env}"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.
AI-assisted analysis of pola-rs/polars@5d8ebabf11 (2026-08-19).
Data as JSON: /api/errors/033b9d56022bd690.
Report an issue: GitHub.