Add MySQL and Postgres port precedence tests; refactor environment variable checks#1872
Conversation
…riable checks - Introduced tests for MySQL and Postgres to verify that the MYSQL_PORT and PGPORT environment variables correctly override default and explicit port settings. - Refactored database connection classes to utilize a new `check_env` utility for environment variable retrieval, enhancing error handling and code clarity. - Updated relevant imports across multiple files to support the new environment variable checking mechanism.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Feel free to merge before #1826, any conflicts should be minimal. |
|
Import sorting is a |
|
Updated my approach. It bothered me that someone passing in the default port would have it overridden, so I set the default port to None and put the default in the init code itself. So now:
Still technically a breaking change but it's so hard to imagine why someone would have their system set up in a way that this would break it so. |
|
That is actually how the check function works. That's why I refactored it and documented it in a pull request, it was kind of hard to understand. |
|
@bmos I was referring there to the behavior of the MySQL/Postgres connector |
What is this change?
check_envutility for environment variable retrieval, enhancing error handling and code clarity.Considerations for discussion
Likely some merge conflicts with #1826. I can wait for that PR to merge and resolve conflicts before merging.
Breaking Changes
Details (if needed)
Technically the change in how port defaults/parameters is resolved is a breaking change. Previously, PGPORT/MYSQL_PORT env variables were effectively ignored when port wasn’t passed, because the port parameter defaults to an integer which evaluates as truthy. So
port or os.environ.get("PGPORT")always used5432even when no parameter was passed and a PG_PORT env variable was set.If anyone was relying on the default port number passed into the mysql or postgres connectors overriding an environmental variable, then they would experience a breaking change. Although it seems pretty odd that someone would set an environmental variable but rely on it being overridden? So I'm not too concerned.
But will ship this with other breaking changes and name it in the release notes just to be cautious.
EDIT: I changed my approach to be less of a breaking change. But it is still a very very slight breaking change.