{"record":{"id":"26d597a8a3a93f67","repo":"influxdata/influxdb","slug":"invalid-database-name-db-name","errorCode":null,"errorMessage":"invalid database name: {db_name}","messagePattern":"invalid database name: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"influxdb3_processing_engine/src/worker/local.rs","lineNumber":559,"sourceCode":"            error!(error = %ErrorOneLine(error), ?self.trigger_definition, %context, \"error running plugin\");\n        }\n    }\n\n    /// Handles the return state from the plugin, writing back lines and handling any errors.\n    /// It returns a vec of error messages that can be used to log or report back to the user.\n    async fn handle_return_state(\n        &self,\n        plugin_return_state: influxdb3_py_api::system_py::PluginReturnState,\n    ) -> Vec<anyhow::Error> {\n        let ingest_time = SystemTime::now()\n            .duration_since(SystemTime::UNIX_EPOCH)\n            .unwrap();\n\n        let mut errors = Vec::new();\n\n        for (db_name, lines) in plugin_return_state.write_db_lines {\n            let Ok(database_name) = DatabaseName::new(db_name.clone()) else {\n                errors.push(anyhow!(\"invalid database name: {db_name}\"));\n                continue;\n            };\n\n            if let Err(e) = self\n                .write_endpoint\n                .write_lp(\n                    WriteTarget::User(database_name),\n                    lines.join(\"\\n\").as_str(),\n                    Time::from_timestamp_nanos(ingest_time.as_nanos() as i64),\n                    false,\n                )\n                .await\n                .with_context(|| format!(\"error writing back lines to {db_name}\"))\n            {\n                errors.push(e);\n            }\n        }\n","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/influxdata/influxdb/blob/d28e26e048401c53cbb98cf2d6ab0cf1e98048ca/influxdb3_processing_engine/src/worker/local.rs#L541-L577","documentation":"After a plugin runs, handle_return_state writes back lines the plugin queued in PluginReturnState.write_db_lines. Each database name must pass DatabaseName::new, which allows only alphanumeric characters plus '/', '_', '-' and a length of 1..=511. An invalid name is collected as anyhow error 'invalid database name: {db_name}' (prefixed with invalid_database_name) while the remaining databases' lines are still processed — so writes to bad names are dropped, not retried.","triggerScenarios":"Python plugin calls context.write_db_lines(db_name, lines) (or LogWriter equivalent) with a name containing a space, dot, or other disallowed character, an empty string, or longer than 511 chars — e.g. write_db_lines('my db', ...) or a name derived from a user-supplied table/host string.","commonSituations":"Deriving the database name from untrusted input (table names, tenant names with dots like 'acme.corp'); assuming '.' is legal because it is common in other systems; names built by templating that can render empty.","solutions":["Sanitize the database name to [A-Za-z0-9_/-] before write_db_lines (e.g. re.sub(r'[^A-Za-z0-9_/-]', '_', db_name))","Check length: 1..=511 characters","Create the target database first with a valid name and reference that constant in the plugin"],"exampleFix":"# before\ncontext.write_db_lines(\"tenant.acme corp\", [\"cpu v=1\"])\n\n# after\nimport re\nsafe = re.sub(r\"[^A-Za-z0-9_/-]\", \"_\", db_name)\ncontext.write_db_lines(safe or \"default_db\", [\"cpu v=1\"])","handlingStrategy":"validation","validationCode":"import re\n\n_DB_NAME = re.compile(r\"^[A-Za-z0-9_/-]{1,511}$\")\n\ndef valid_db_name(name: str) -> bool:\n    return bool(_DB_NAME.fullmatch(name))\n\nif valid_db_name(db_name):\n    context.write_db_lines(db_name, lines)\nelse:\n    logger.warning(\"dropping lines for invalid db name %r\", db_name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allow only [A-Za-z0-9_/-] and length 1..=511 when deriving database names from input","Reference database names as constants created via the API, not strings assembled at runtime","Unit-test the plugin's name-mapping logic against hostile inputs (spaces, dots, empty)"],"tags":["influxdb","processing-engine","python","database-name","validation"],"backgroundTag":"invalid-database-name","analyzedSha":"d28e26e048401c53cbb98cf2d6ab0cf1e98048ca","analyzedAt":"2026-08-16T19:53:34.623Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}