fix: URL-Encode Postgres Password #3163
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
There's a bug in Pydantic V2 that doesn't properly URL-encode Postgres passwords. They used to work fine in V1, for whatever reason. This specifically affects passwords with any of these characters, at a minimum:
,#/?
(see the linked ticket below).This PR attempts to create the Postgres URL normally, and if it fails, attempts to URL parse it ourselves. I did it this way in case there's some unintended side-effect, I didn't want to bork any other users.apparently using urllib.parse.quote_plus is the right way to do it: https://stackoverflow.com/questions/1423804/writing-a-connection-string-when-password-contains-special-charactersThe related Pydantic bug: pydantic/pydantic#8061
Which issue(s) this PR fixes:
(REQUIRED)
N/A, raised in Discord
Special notes for your reviewer:
(fill-in or delete this section)
Hopefully this covers all use-cases, but worst-case users can choose passwords without problematic characters (though I fully understand why we want to avoid that, since postgres does support them).
Testing
(fill-in or delete this section)
Added a test