Repository navigation
Don't modify the params hash passed to Client.new - #39
Open
Divyanshu-2907 wants to merge 1 commit into
Open
Divyanshu-2907 wants to merge 1 commit into
Divyanshu-2907 wants to merge 1 commit into
Conversation
The constructor deleted :timeout and :persistent from the caller's hash, so a reused config hash gave the second client the default 120s timeout and a persistent socket. A frozen hash raised FrozenError. Work on a dup of params instead. dup is used rather than clone because clone keeps the frozen state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Client#initializedeletes:timeoutand:persistentstraight from the hash the caller passes in. That causes two problems.If you build two clients from the same config hash, the second one silently loses those settings and falls back to a 120s timeout and a persistent socket:
And a frozen config hash (common for constants) raises:
The fix is to work on
params.dupand take:timeoutand:persistentout of the copy. I usedduprather thancloneon purpose, becauseclonekeeps the frozen flag and would still raise on a frozen hash.@paramsis still frozen at the end like before, so nothing changes for callers who pass a fresh hash.I added
spec/serpapi/client/constructor_spec.rb. Those specs only build clients and never hit the API, so they run without a real key.PR #22 touched this area too, but it was closed along with a lot of other changes. This one is just the constructor fix, so it's easy to review on its own.