Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass URI directly to PQconnectdb #388

Closed
wants to merge 3 commits into from

Conversation

levkk
Copy link

@levkk levkk commented Jun 24, 2021

Fixes #387

@larskanis
Copy link
Collaborator

Unfortunately all tests fail. Could you please fix this?

@levkk
Copy link
Author

levkk commented Jun 25, 2021

Unfortunately all tests fail. Could you please fix this?

This is always how I like to start my PRs...tells people I mean business ;) Let me try and fix this mess I made...

@levkk
Copy link
Author

levkk commented Jun 25, 2021

Local tests pass 👍 I excluded the test that allowed the user to override user, password, and other URI-specific parameters when a URI and an options hash is passed in because that would force the library to parse the URI and will throw the bad URI error if multiple database hosts are used. This is a slight behavior change, I would expect this to be somewhat breaking to some apps that use this strange feature.

@cbandy
Copy link
Contributor

cbandy commented Jun 29, 2021

As I recall, URI and Hash are accepted together so the caller can set/override parameters like sslmode or connect_timeout without knowing the content or format of the connection string. It doesn't look like this behavior was documented outside of tests.

Should the caller have to think differently about user, dbname, etc?

@@ -49,8 +49,7 @@ def self::parse_connect_args( *args )
if args.length == 1
case args.first
when URI, /\A#{URI::ABS_URI_REF}\z/
uri = URI(args.first)
options.merge!( Hash[URI.decode_www_form( uri.query )] ) if uri.query
uri = args.first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have uri either always be URI or always be String. We don't use the structure of URI later on, so converting to String seems appropriate here.

uri = String(args.first)

if uri.is_a? URI
uri = uri.to_s
end
if uri.include?("?")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like ? does not definitely indicate there is a query.

> URI('postgres://u?n:pw@localhost')              
=> #<URI::Generic postgres://u?n:pw@localhost>

> URI('postgres://un:p?w@localhost')
Traceback (most recent call last):
URI::InvalidURIError (bad URI(is not URI?): "postgres://un:p?w@localhost")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is interesting...and unfortunate. At the same time, I can't parse the URI that may have two hosts or more because that's definitely not valid. Hmm.

@larskanis
Copy link
Collaborator

I overhauled the connection string parser to support URIs with multiple hosts in 5e8c911 . It takes a tradeoff by not modifying the parts of the URI, that were given to the API call, but extends it with additional parameters like hostaddr and fallback_application_name.

@larskanis larskanis closed this Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple hosts are not supported because it's not a valid URI
4 participants