FIX: default with_session client options#3
Conversation
ce8b579 to
6720a68
Compare
JanEbbing
left a comment
There was a problem hiding this comment.
Thanks for your work! This looks good to me overall, just 2 small nits.
I will also look to add a test case that uses with_session to make 2 requests in a VCR on top of your changes.
| @@ -0,0 +1,63 @@ | |||
| # frozen_string_literal: true | |||
There was a problem hiding this comment.
Nit 1: please add this copyright header for new files
# Copyright 2024 DeepL SE (https://www.deepl.com)
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
| @@ -0,0 +1,63 @@ | |||
| # frozen_string_literal: true | |||
|
|
|||
There was a problem hiding this comment.
Nit 2: IMO this file should go under spec/http_client_options_spec.rb - integration_tests is reserved for files that make actual web requests to the API, and the spec/ folder in general emulates the structure of the source code in lib/.
|
|
||
| require 'spec_helper' | ||
|
|
||
| describe DeepL::HTTPClientOptions do |
The default `HTTPClientOptions.new()` parameter in `with_session` method raises an error. According to the [README](https://github.com/DeepLcom/deepl-rb/blob/1f63db3b704ec532c0b970a52fb8ec90c6986e84/README.md?plain=1#L344-L350) it should be possible to call `with_session` without passing any arguments.
6720a68 to
ee33e3e
Compare
|
@JanEbbing Thanks for quickly checking it out! I have a question, maybe you have an idea of what's going on. Below you can see the previous @@ -19,8 +19,8 @@ def translate_single(text, source_lang, target_lang, options = DEFAULT_OPTIONS)
end
def translate_multiple(text, source_lang, target_langs, options = DEFAULT_OPTIONS)
- promises = target_langs.map do |target_lang|
- Concurrent::Promises.future do
+ with_session(DeepL::HTTPClientOptions.new({}, nil)) do |_session|
+ target_langs.to_h do |target_lang|
translation = translate(text, local_to_external(source_lang), local_to_external(target_lang), options.to_h.deep_dup)
[external_to_local(target_lang), translation.text]
rescue DeepL::Exceptions::Error => e
@@ -28,10 +28,6 @@ def translate_multiple(text, source_lang, target_langs, options = DEFAULT_OPTION
[external_to_local(target_lang), nil]
end
end
-
- results = Concurrent::Promises.zip(*promises).value!
-
- results.to_h
end |
|
I'll look into this tomorrow - I did slightly change how the requests are made internally, but I dont think it should cause issues for this use case. |
|
Hi, I cannot reproduce any issues with the following code: But I need to read a bit more to exclude any thread safety issues, as the |
|
This looks related getsentry/sentry-ruby#1696 For me the error pops up in production reliably, maybe it's related to yjit, which is enabled only in prod in my case, e.g. |
|
I have the same |
The default
HTTPClientOptions.new()parameter inwith_sessionmethod raises an error. According to the README it should be possible to callwith_sessionwithout passing any arguments.