@@ -27,21 +27,25 @@ class Postgres(PostgresCore, Alchemy, DatabaseConnector):
2727 db: str
2828 Required if env variable ``PGDATABASE`` not populated
2929 port: int
30- Required if env variable ``PGPORT`` not populated.
30+ If omitted or ``None``, uses ``PGPORT`` when set, otherwise 5432. If passed
31+ (including ``5432``), the argument takes precedence over ``PGPORT``.
3132 timeout: int
3233 Seconds to timeout if connection not established.
3334
3435 """
3536
36- def __init__ (self , username = None , password = None , host = None , db = None , port = 5432 , timeout = 10 ):
37+ def __init__ (self , username = None , password = None , host = None , db = None , port = None , timeout = 10 ):
3738 super ().__init__ ()
3839
3940 self .username = check_env .check ("PGUSER" , username , optional = True )
4041 self .password = check_env .check ("PGPASSWORD" , password , optional = True )
4142 self .host = check_env .check ("PGHOST" , host , optional = True )
4243 self .db = check_env .check ("PGDATABASE" , db , optional = True )
43- env_port = check_env .check ("PGPORT" , None , optional = True )
44- self .port = int (env_port ) if env_port is not None else port
44+ if port is not None :
45+ self .port = port
46+ else :
47+ env_port = check_env .check ("PGPORT" , None , optional = True )
48+ self .port = int (env_port ) if env_port is not None else 5432
4549
4650 # Check if there is a pgpass file. Psycopg2 will search for this file first when
4751 # creating a connection.
0 commit comments