{"record":{"id":"051986ef8add9b1e","repo":"mem0ai/mem0","slug":"both-username-and-password-must-be-provided-to","errorCode":null,"errorMessage":"Both 'username' and 'password' must be provided together for authentication","messagePattern":"Both 'username' and 'password' must be provided together for authentication","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/configs/vector_stores/cassandra.py","lineNumber":38,"sourceCode":"        None,\n        description=\"Path to secure connect bundle for DataStax Astra DB\"\n    )\n    protocol_version: int = Field(4, description=\"CQL protocol version\")\n    load_balancing_policy: Optional[Any] = Field(\n        None,\n        description=\"Custom load balancing policy object\"\n    )\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def check_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:\n        \"\"\"Validate authentication parameters.\"\"\"\n        username = values.get(\"username\")\n        password = values.get(\"password\")\n\n        # Both username and password must be provided together or not at all\n        if (username and not password) or (password and not username):\n            raise ValueError(\n                \"Both 'username' and 'password' must be provided together for authentication\"\n            )\n\n        return values\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def check_connection_config(cls, values: Dict[str, Any]) -> Dict[str, Any]:\n        \"\"\"Validate connection configuration.\"\"\"\n        secure_connect_bundle = values.get(\"secure_connect_bundle\")\n        contact_points = values.get(\"contact_points\")\n\n        # Either secure_connect_bundle or contact_points must be provided\n        if not secure_connect_bundle and not contact_points:\n            raise ValueError(\n                \"Either 'contact_points' or 'secure_connect_bundle' must be provided\"\n            )\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/configs/vector_stores/cassandra.py#L20-L56","documentation":"Raised by the Cassandra vector store config when username and password are partially supplied. Cassandra auth in mem0 is all-or-nothing: either both credentials are set (RoleBasedAuthenticator) or both are absent (no auth). Supplying exactly one is treated as a configuration bug.","triggerScenarios":"Creating CassandraConfig with 'username' but no 'password', or 'password' but no 'username'. Falsy-vs-truthy asymmetry: one key present with a non-empty value while the other is missing/None/empty triggers it.","commonSituations":"Secrets loaded from different env vars where one is unset (CASSANDRA_USER set, CASSANDRA_PASSWORD missing in CI); trimming a password to empty string via a bad .strip() or templating step; switching a cluster from auth to no-auth and removing only one key.","solutions":["Provide both 'username' and 'password' together in the config","If the cluster has no authentication, remove both keys entirely","Check that the environment/template supplying the credentials actually populates both values (log their presence, never their content)","Default both to None in code when either is missing so the pair stays consistent"],"exampleFix":"# before\nCassandraConfig(contact_points=[\"h\"], username=\"cassandra\")\n\n# after\nCassandraConfig(contact_points=[\"h\"], username=\"cassandra\", password=os.environ[\"CASSANDRA_PASSWORD\"])","handlingStrategy":"validation","validationCode":"def validate_cassandra_auth(cfg: dict) -> None:\n    u, p = bool(cfg.get(\"username\")), bool(cfg.get(\"password\"))\n    if u != p:\n        raise RuntimeError(\"Cassandra username and password must be provided together or both omitted\")","typeGuard":"def cassandra_auth_pair_ok(cfg: dict) -> bool:\n    return bool(cfg.get(\"username\")) == bool(cfg.get(\"password\"))","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    CassandraConfig(**cfg)\nexcept ValidationError as e:\n    if \"must be provided together\" in str(e):\n        # either fill the missing half or drop both, then retry\n        ...","preventionTips":["Source both credentials from one secret-fetch so they succeed or fail together","Check secret presence (not values) in logs before building config","When disabling auth, remove both keys in the same commit"],"tags":["pydantic","configuration","vector-store","cassandra","authentication"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}