{"record":{"id":"ad7b8a78cd5bc1c2","repo":"cocoindex-io/cocoindex","slug":"invalid-neo4j-database-name-database-r-must-ma","errorCode":null,"errorMessage":"Invalid Neo4j database name: {database!r}. Must match [A-Za-z0-9._-]+.","messagePattern":"Invalid Neo4j database name: (.+?)\\. Must match \\[A-Za-z0-9\\._-\\]\\+\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_target.py","lineNumber":150,"sourceCode":"            uri=\"bolt://localhost:7687\",\n            auth=(\"neo4j\", \"cocoindex\"),\n            database=\"neo4j\",\n        )\n        builder.provide(NEO4J_DB, factory)\n    \"\"\"\n\n    def __init__(\n        self,\n        uri: str,\n        *,\n        auth: tuple[str, str] | None = None,\n        database: str = \"neo4j\",\n    ) -> None:\n        # Database identifiers in Neo4j 5 may contain hyphens and dots; be\n        # less strict than the Cypher identifier validator. Just reject the\n        # obviously dangerous characters so we don't have to escape.\n        if not re.match(r\"^[A-Za-z0-9._-]+$\", database):\n            raise ValueError(\n                f\"Invalid Neo4j database name: {database!r}. \"\n                \"Must match [A-Za-z0-9._-]+.\"\n            )\n        self._uri = uri\n        self._auth = auth\n        self._database = database\n\n    @property\n    def database(self) -> str:\n        return self._database\n\n    async def acquire(self) -> _GraphHandle:\n        \"\"\"Return a graph handle ready to issue ``query(cypher, params)``.\"\"\"\n        driver = _neo4j.AsyncGraphDatabase.driver(self._uri, auth=self._auth)\n        return _GraphHandle(driver, self._database)\n\n\n# ---------------------------------------------------------------------------","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L132-L168","documentation":"This ValueError is raised by the Neo4j target connector's __init__ when the database name contains characters outside [A-Za-z0-9._-]. The connector deliberately rejects characters that would require escaping in Cypher or connection settings, rather than escaping them. Neo4j 5 database identifiers may contain hyphens and dots, which the regex allows.","triggerScenarios":"Constructing the Neo4j target with database containing whitespace, slashes, quotes, or other special characters — e.g. database=\"my db\", database=\"db/2024\", or an interpolated name built from a URL segment or environment variable with stray characters.","commonSituations":"Passing a full DSN or connection string fragment as the database name; an env var with trailing whitespace or newline; building the name from user input without sanitization; confusing database name with URI path.","solutions":["Pass a plain database identifier matching [A-Za-z0-9._-]+, e.g. \"neo4j\" or \"my-db.v2\".","Strip/sanitize the source value: re.sub(r'[^A-Za-z0-9._-]', '_', name) or .strip() before constructing.","Confirm you are passing the database name, not a URI or file path."],"exampleFix":"// before\nNeo4jTarget(uri=uri, auth=auth, database=\"my database/one\")\n// after\nNeo4jTarget(uri=uri, auth=auth, database=\"my_database_one\")","handlingStrategy":"validation","validationCode":"import re\nassert re.match(r\"^[A-Za-z0-9._-]+$\", database), f\"bad database name: {database!r}\"","typeGuard":null,"tryCatchPattern":"try:\n    target = Neo4jTarget(uri=uri, auth=auth, database=database)\nexcept ValueError as e:\n    database = re.sub(r\"[^A-Za-z0-9._-]\", \"_\", database.strip())\n    target = Neo4jTarget(uri=uri, auth=auth, database=database)","preventionTips":["Sanitize database names derived from env vars or user input with .strip() and a whitelist regex","Never pass a DSN/path where a database name is expected","Keep database names as explicit config, not interpolated from URLs"],"tags":["neo4j","validation","identifier","config"],"backgroundTag":"invalid-identifier-format","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}