{"record":{"id":"c31a31254bf3d062","repo":"influxdata/influxdb","slug":"partition-key-generation-error","errorCode":null,"errorMessage":"partition key generation error","messagePattern":"partition key generation error","errorType":"error_code","errorClass":"PartitionKeyError","httpStatus":null,"severity":"error","filePath":"core/partition/src/lib.rs","lineNumber":48,"sourceCode":"use self::template::Template;\npub use self::traits::{Batch, PartitioningColumn, TimeColumnError};\n\n/// An error generating a partition key for a row.\n#[derive(Debug, Error, PartialEq, Eq, Clone)]\npub enum PartitionKeyError {\n    /// The partition template defines a [`Template::TimeFormat`] part, but the\n    /// provided strftime formatter is invalid.\n    #[error(\"invalid strftime format in partition template\")]\n    InvalidStrftime,\n\n    /// The partition template defines a [`Template::TagValue`] part, but the\n    /// column type is not \"tag\".\n    #[error(\"tag value partitioner does not accept input columns of type {0}\")]\n    TagValueNotTag(String),\n\n    /// A \"catch all\" error for when a formatter returns [`std::fmt::Error`],\n    /// which contains no context.\n    #[error(\"partition key generation error\")]\n    FmtError(#[from] std::fmt::Error),\n}\n\n/// Returns an iterator identifying consecutive ranges for a given partition key\npub fn partition_batch<'a, T>(\n    batch: &'a T,\n    template: &'a TablePartitionTemplateOverride,\n) -> impl Iterator<Item = (Result<String, PartitionKeyError>, Range<usize>)> + 'a\nwhere\n    T: Batch,\n{\n    let parts = template.len();\n    if parts > MAXIMUM_NUMBER_OF_TEMPLATE_PARTS {\n        panic!(\n            \"partition template contains {parts} parts, which exceeds the maximum of {MAXIMUM_NUMBER_OF_TEMPLATE_PARTS} parts\"\n        );\n    }\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/partition/src/lib.rs#L30-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet keys: Vec<_> = partition_keys(&batch, template.parts()).collect();\n// after\nif batch.time_column().is_none() { return Err(anyhow!(\"missing time column\")); }\nlet keys: Vec<_> = partition_keys(&batch, template.parts()).collect();","handlingStrategy":"try-catch","validationCode":"// ensure inputs are renderable before partitioning\ndebug_assert!(batch.time_column().is_some());\nfor part in template.parts() {\n    if let TemplatePart::TagColumn(name) = part {\n        assert!(batch.schema().column_with_name(name).is_some(), \"tag column {name} missing\");\n    }\n}","typeGuard":"fn is_fmt_error(e: &PartitionKeyError) -> bool { matches!(e, PartitionKeyError::FmtError(_)) }","tryCatchPattern":"match partition_keys(&batch, template.parts()).collect::<Result<Vec<_>, _>>() {\n    Ok(keys) => use_keys(keys),\n    Err(PartitionKeyError::FmtError(_)) => log::warn!(\"formatter failed rendering partition key; skipping batch\"),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["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"],"tags":["rust","partitioning","formatting"],"backgroundTag":"invalid-argument-format","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}