{"record":{"id":"6cae6c85ae2c9adf","repo":"nicolargo/glances","slug":"replication-factor-must-be-a-positive-integer","errorCode":null,"errorMessage":"replication_factor must be a positive integer","messagePattern":"replication_factor must be a positive integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"glances/exports/glances_cassandra/__init__.py","lineNumber":69,"sourceCode":"        self.username = None\n        self.password = None\n\n        # Load the Cassandra configuration file section\n        self.export_enable = self.load_conf(\n            'cassandra',\n            mandatories=['host', 'port', 'keyspace'],\n            options=['protocol_version', 'replication_factor', 'table', 'username', 'password'],\n        )\n        if not self.export_enable:\n            sys.exit(2)\n\n        # Validate CQL identifiers to prevent injection via config values\n        try:\n            self.keyspace = _validate_cql_identifier(self.keyspace, 'keyspace')\n            self.table = _validate_cql_identifier(self.table, 'table')\n            self.replication_factor = int(self.replication_factor)\n            if self.replication_factor < 1:\n                raise ValueError(\"replication_factor must be a positive integer\")\n        except ValueError as e:\n            logger.error(f\"Cassandra configuration error: {e}\")\n            self.export_enable = False\n            return\n\n        # Init the Cassandra client\n        self.cluster, self.session = self.init()\n\n    def init(self):\n        \"\"\"Init the connection to the Cassandra server.\"\"\"\n        if not self.export_enable:\n            return None\n\n        # if username and/or password are not set the connection will try to connect with no auth\n        auth_provider = PlainTextAuthProvider(username=self.username, password=self.password)\n\n        # Cluster\n        try:","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/exports/glances_cassandra/__init__.py#L51-L87","documentation":"The Cassandra export requires replication_factor to parse as an int >= 1; anything else (0, negative, non-numeric string) raises this ValueError, which is caught in the same __init__, logged as 'Cassandra configuration error', and results in the export being disabled (export_enable = False). Glances itself continues to run.","triggerScenarios":"Setting export_cassandra_replication_factor to 0, -1, 'two', or omitting a default that resolves falsy in glances.conf. Also triggered if the config value has stray whitespace or quotes that break int().","commonSituations":"Single-node test clusters where users set replication_factor=0 thinking it means 'no replication'; config typos like replication_factor = 1; environments with more than one datacenter but a simple-int config.","solutions":["Set a positive integer, e.g. export_cassandra_replication_factor=1 (or 3 for production clusters).","Verify the key in glances.conf is spelled export_cassandra_replication_factor and holds a bare integer.","Check glances.log for 'Cassandra configuration error' to confirm validation failed and the export was disabled."],"exampleFix":"# before\n[export_cassandra]\nreplication_factor=0\n\n# after\n[export_cassandra]\nreplication_factor=1","handlingStrategy":"validation","validationCode":"rf = int(config.get('replication_factor', 1))\nassert rf >= 1, 'replication_factor must be >= 1'","typeGuard":"def is_valid_replication_factor(v) -> bool:\n    try:\n        return int(v) >= 1\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["Single-node clusters: use replication_factor=1, never 0.","Keep the value a bare integer in glances.conf (no quotes/units).","After config changes, verify in glances.log that the export actually enabled."],"tags":["cassandra","config-validation","replication"],"backgroundTag":"config-value-out-of-range","analyzedSha":"a240d8dfb3105a38b5964357ec21768594b0e83e","analyzedAt":"2026-08-27T19:15:19.178Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}