influxdata/influxdb · error · PartitionKeyError
partition key generation error
Error message
partition key generation error
What it means
PartitionKeyError::FmtError is a catch-all variant wrapping std::fmt::Error, thrown when a partition key formatter fails while rendering a template part into the partition key string. Because std::fmt::Error carries no context, the library rebrands it as 'partition key generation error'. It indicates the formatting machinery (e.g. a strftime formatter or Display impl) failed mid-render.
Solutions
- Check which template part fails and simplify the partition template to isolate the offending formatter
- Verify tag values and time column data are valid before calling partition_batch
- If a custom formatter is involved, fix its write implementation to not return Err
Example fix
// before
let keys: Vec<_> = partition_keys(&batch, template.parts()).collect();
// after
if batch.time_column().is_none() { return Err(anyhow!("missing time column")); }
let keys: Vec<_> = partition_keys(&batch, template.parts()).collect(); Defensive patterns
Strategy: try-catch
Validate before calling
// ensure inputs are renderable before partitioning
debug_assert!(batch.time_column().is_some());
for part in template.parts() {
if let TemplatePart::TagColumn(name) = part {
assert!(batch.schema().column_with_name(name).is_some(), "tag column {name} missing");
}
} Type guard
fn is_fmt_error(e: &PartitionKeyError) -> bool { matches!(e, PartitionKeyError::FmtError(_)) } Try / catch
match partition_keys(&batch, template.parts()).collect::<Result<Vec<_>, _>>() {
Ok(keys) => use_keys(keys),
Err(PartitionKeyError::FmtError(_)) => log::warn!("formatter failed rendering partition key; skipping batch"),
Err(e) => return Err(e.into()),
} Prevention
- Validate the batch schema (time and tag columns) before partitioning
- Keep formatters infallible; never thread fallible I/O into Display impls
- Log template parts alongside errors to speed up diagnosis
When it happens
Trigger: Calling partition_batch/partition_keys with a template part whose formatter returns Err from write_str/write_fmt — e.g. an underlying formatter erroring while rendering a tag value or timestamp.
Common situations: A custom or I/O-backed formatter hitting an error; rarely seen in practice since most formatters are infallible; may surface when a template part's Display impl delegates to something fallible.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Error converting partition_template
- Expected parts in key due to template passed in, found …
- missing required specifier(s) in time format of partition…
- non-identical consecutive keys
- number of buckets in partition template must be in range
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/c31a31254bf3d062.
Report an issue: GitHub.
Appendix: source
Thrown at core/partition/src/lib.rs:48
use self::template::Template;
pub use self::traits::{Batch, PartitioningColumn, TimeColumnError};
/// An error generating a partition key for a row.
#[derive(Debug, Error, PartialEq, Eq, Clone)]
pub enum PartitionKeyError {
/// The partition template defines a [`Template::TimeFormat`] part, but the
/// provided strftime formatter is invalid.
#[error("invalid strftime format in partition template")]
InvalidStrftime,
/// The partition template defines a [`Template::TagValue`] part, but the
/// column type is not "tag".
#[error("tag value partitioner does not accept input columns of type {0}")]
TagValueNotTag(String),
/// A "catch all" error for when a formatter returns [`std::fmt::Error`],
/// which contains no context.
#[error("partition key generation error")]
FmtError(#[from] std::fmt::Error),
}
/// Returns an iterator identifying consecutive ranges for a given partition key
pub fn partition_batch<'a, T>(
batch: &'a T,
template: &'a TablePartitionTemplateOverride,
) -> impl Iterator<Item = (Result<String, PartitionKeyError>, Range<usize>)> + 'a
where
T: Batch,
{
let parts = template.len();
if parts > MAXIMUM_NUMBER_OF_TEMPLATE_PARTS {
panic!(
"partition template contains {parts} parts, which exceeds the maximum of {MAXIMUM_NUMBER_OF_TEMPLATE_PARTS} parts"
);
}
View on GitHub (pinned to 06200ef96b)