{"record":{"id":"10a7061cbd25c5ef","repo":"ruvnet/RuView","slug":"database-port-must-be-between-1-and-65535","errorCode":null,"errorMessage":"Database port must be between 1 and 65535","messagePattern":"Database port must be between 1 and 65535","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/config/settings.py","lineNumber":231,"sourceCode":"        \"\"\"Validate port number.\"\"\"\n        if not 1 <= v <= 65535:\n            raise ValueError(\"Port must be between 1 and 65535\")\n        return v\n    \n    @field_validator(\"workers\")\n    @classmethod\n    def validate_workers(cls, v):\n        \"\"\"Validate worker count.\"\"\"\n        if v < 1:\n            raise ValueError(\"Workers must be at least 1\")\n        return v\n    \n    @field_validator(\"db_port\")\n    @classmethod\n    def validate_db_port(cls, v):\n        \"\"\"Validate database port.\"\"\"\n        if not 1 <= v <= 65535:\n            raise ValueError(\"Database port must be between 1 and 65535\")\n        return v\n    \n    @field_validator(\"redis_port\")\n    @classmethod\n    def validate_redis_port(cls, v):\n        \"\"\"Validate Redis port.\"\"\"\n        if not 1 <= v <= 65535:\n            raise ValueError(\"Redis port must be between 1 and 65535\")\n        return v\n    \n    @field_validator(\"db_pool_size\")\n    @classmethod\n    def validate_db_pool_size(cls, v):\n        \"\"\"Validate database pool size.\"\"\"\n        if v < 1:\n            raise ValueError(\"Database pool size must be at least 1\")\n        return v\n    ","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/config/settings.py#L213-L249","documentation":"This ValueError is raised by the Pydantic field_validator validate_db_port on the Settings model in archive/v1/src/config/settings.py. When the db_port field (default 5432) is set outside the range 1..65535, the validator raises ValueError, which Pydantic v2 re-wraps into a ValidationError at Settings instantiation time. It is a fail-fast guard so an invalid port never reaches SQLAlchemy connection setup.","triggerScenarios":"Constructing the Settings object (directly or via get_settings()) while db_port resolves to 0, a negative number, or a value above 65535. Typical inputs: Settings(db_port=0), the environment variable DB_PORT=70000, or a docker-compose/`.env` file that defines DB_PORT to an out-of-range value.","commonSituations":"Setting DB_PORT=0 intending to disable the database; pasting a full connection string into the port variable; CI pipelines or container images exporting stale DB_PORT values; mis-typed values like DB_PORT=-5432 after an edit; port values copied from an IANA-registered port above 65535 (e.g. mistaking a container hash for a port).","solutions":["Set db_port to a valid TCP port, normally 5432 for PostgreSQL (e.g. DB_PORT=5432 in `.env`).","Check the runtime environment for DB_PORT overrides: print the resolved value with `echo $DB_PORT` (or the container/compose env section) before the app starts.","If the port comes from a URL string, parse it with urllib.parse and pass only the numeric `.port`, or set database_url directly so db_port is unused.","If you deliberately want to disable the DB, do not use port 0; instead leave environment=development (SQLite default) or set enable_database_failsafe and omit db_host/db_user."],"exampleFix":"# before\nDB_PORT=0\nsettings = Settings()  # ValidationError: Database port must be between 1 and 65535\n\n# after\nDB_PORT=5432\nsettings = Settings()","handlingStrategy":"validation","validationCode":"import os\n\nraw = os.environ.get('DB_PORT', '5432')\ntry:\n    db_port = int(raw)\nexcept ValueError:\n    raise SystemExit(f'DB_PORT must be an integer, got {raw!r}')\nif not 1 <= db_port <= 65535:\n    raise SystemExit(f'DB_PORT must be 1..65535, got {db_port}')","typeGuard":null,"tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    settings = Settings()\nexcept ValidationError as e:\n    # e.errors()[0]['msg'] == 'Value error, Database port must be between 1 and 65535'\n    for err in e.errors():\n        print(err['loc'], err['msg'])\n    raise SystemExit('Fix DB_PORT before starting')","preventionTips":["Validate DB_PORT in the deployment script or entrypoint before the app imports settings.","Use numeric-only inputs for port env vars; never paste URLs into them.","Add a CI config-lint step that asserts every *_PORT var parses to 1..65535."],"tags":["config","pydantic","database","validation","env-vars"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}