Constructor symbolize_names defaults are ignored
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Read lib/serpapi/client.rb, especially the constructor option documented at line 60 and process_json_response at line 354. Start by checking how per-call parser options are read and how constructor defaults are stored; reproduce with the offline Ruby script in the issue. Done when constructor symbolize_names: false produces String keys, per-call settings override it, and omitted settings retain Symbol keys, with tests covering the behavior and the noted error-key interaction.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Basic checks
- I searched existing issues, open and closed, and this has not been reported (reported previously in author-withdrawn #22; no active parser-precedence fix)
- I can reproduce this consistently on
master - This is a serpapi-ruby bug, not my application code
What's broken?
Client.new(symbolize_names: false) is documented in
lib/serpapi/client.rb:60, but JSON responses still have Symbol keys.
process_json_response at line 354 reads only the method-call params.
Constructor defaults are never consulted.
This affects searches, account responses, archived searches, and image
uploads. search_archive cannot receive a per-call parser option, so its
constructor default is especially important.
Closed #22 included this
fix alongside many unrelated changes. Its author closed it and deleted
the branch. This is a focused follow-up, not a new discovery.
Open #39 fixes caller Hash
mutation; #42 changes
error policy and error metadata. Neither fixes parser-option precedence.
One interaction to decide on: error detection reads Symbol keys only
(data.key?(:error)). Per-call symbolize_names: false already has this
gap on master. Once the constructor option works, those clients hit it
as well: a 200 response with an error key is returned instead of
raised, and a 401 raises with serpapi_error set to nil. With #42
applied, constructor false gives the same results as the default for
all three cases I checked. I suggest this fix lands after #42 or together
with it.
How to reproduce
From the repository root, after bundle install. This replaces the
transport in this process and makes no network request:
bundle exec ruby -Ilib - <<'RUBY'
require 'serpapi'
response = Struct.new(:status, :headers, :body).new(
200, { 'Content-Type' => 'application/json' }, '{"search_metadata":{"id":"offline"}}'
)
transport = Object.new
transport.define_singleton_method(:get) { |*_args, **_options| response }
HTTP.define_singleton_method(:timeout) { |_timeout| transport }
client = SerpApi::Client.new(persistent: false, symbolize_names: false)
p client.search(q: 'coffee').keys
RUBY
Expected behavior
["search_metadata"]. Per-call settings override constructor settings,
and absent settings keep the default Symbol keys.
What actually happened
[:search_metadata]
I have a small local fix with tests and can open a PR.
Environment
- Ruby 3.4.4, macOS arm64
- serpapi-ruby
masterat786baa6848020df031abed734ed7ff03af3a6560 - HTTP.rb 5.3.1, RSpec 3.13.2
- No API credentials, external requests, or search credits used
- Vorherrschende Sprache
- Ruby
- Sterne
- 43
- Forks
- 27
- Ø Merge
- 3 T. 21 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus serpapi/serpapi-ruby
-
Mixed String and Symbol overrides send duplicate parametersEvtl. vergeben @yorzi hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
serpapi/serpapi-ruby#45 ·
Alle Issues in serpapi/serpapi-ruby
Ähnliche Issues
-
good first issue help wanted
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
erkamyaman/rust-anything#702 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
slovensko-digital/govbox-pro#986 ·
Maintainer antworten meist innerhalb von 1 Tag
-
community
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
newrelic/newrelic-ruby-agent#3737 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag