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

Update faraday to 2.12, remove deprecated faraday_middleware gem #393

Merged
merged 9 commits into from
Feb 11, 2025

Conversation

eikes
Copy link
Collaborator

@eikes eikes commented Jun 4, 2024

No description provided.

end

it 'raise a proper error' do
expect { client_response }.to raise_error(Faraday::ParsingError)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This error can not be raised in this spec anymore. We are stubbing the response which Faraday returns after the middleware is applied. So no JSON parsing takes place anymore.

@@ -40,7 +40,7 @@ def call(client, model, args = [], options = {})
params: options[:params]
)

return if parsed_response.nil?
return if Support.blank?(parsed_response)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When a response is an empty string, it will not be cast to nil anymore, so we check for empty? or nil?

@phylor
Copy link
Collaborator

phylor commented Jun 10, 2024

@eikes I quickly tested this in the two projects I'm working on and I do have failing tests. So there seems to be a behavioral change. Let me know if this PR is review ready, I'll then check what's going on!

@eikes
Copy link
Collaborator Author

eikes commented Jun 10, 2024

@phylor Yes, it's ready for review, using an outdated Faraday version was a problem for me. Please let me know how or what is failing. I can help debug if you want me to.

@phylor
Copy link
Collaborator

phylor commented Jun 10, 2024

@phylor Yes, it's ready for review, using an outdated Faraday version was a problem for me. Please let me know how or what is failing. I can help debug if you want me to.

It is a testing issue. I'm not so sure if this will ever happen in production code.

The behavioral change is that we now return nil from create/update/delete API methods, when the HTTP response is {}. Before, we initialized an empty model (e.g. we called Ioki::Model::Operator::Vehicle.new({})).

If we were defensive, we could change the condition to something like return if parsed_response.nil? || (parsed_response.is_a?(String) && parsed_response.empty?).

I'm not sure how often that happens in real code. It happens in our test code as we return an empty hash in mocked API calls when we're not interested in the response. We used to get an empty model back, i.e. we could still call all methods on it (they do return nil then). The new behavior is that the response is nil and we can't call methods on it.

I'm also not sure if it's more logical/correct to return nil instead of an empty model. Maybe it is?

I thought about what happens when the API returns []. But I believe the relevant endpoints do not support arrays anyways.

I don't have a strong opinion - I'm slightly leaning towards your proposed solution, as returning nil instead of an empty model seems to be more correct.

@eikes What do you think?

@eikes
Copy link
Collaborator Author

eikes commented Jun 11, 2024

@phylor Two things come to mind:

  1. We should define the behaviour and create a test for it in this repository which makes sure that it works as defined.
  2. I think that an empty JSON object {} is still a valid response and should in fact be turned into an instance of the ruby class the user expects, even if all attributes are empty.

@phylor
Copy link
Collaborator

phylor commented Jun 12, 2024

@phylor Two things come to mind:

  1. We should define the behaviour and create a test for it in this repository which makes sure that it works as defined.
  2. I think that an empty JSON object {} is still a valid response and should in fact be turned into an instance of the ruby class the user expects, even if all attributes are empty.

Okay, then let's agree that we don't change the existing behavior. At least not for the empty hash.

@phylor phylor force-pushed the update-faraday-2-9 branch from 244f78f to 4808f8e Compare February 4, 2025 17:45
@phylor phylor changed the base branch from main to fix/retry-more-exceptions February 4, 2025 17:46
The current behavior depends on the response:

- response `""`: `nil` as model
- response `nil`: `nil` as model
- response `{}`: empty model
@phylor phylor force-pushed the update-faraday-2-9 branch from 4808f8e to 5aaad00 Compare February 4, 2025 17:52
@phylor
Copy link
Collaborator

phylor commented Feb 4, 2025

@eikes I changed a couple of things to make the update work without breaking existing behavior.

Our behavior is inconsistent though. It depends on what the response is. If the response is invalid JSON, we return nil, otherwise an empty model. We should probably fix that at some point, but it would be a breaking change.

@phylor phylor requested a review from rmehner February 4, 2025 17:55
Base automatically changed from fix/retry-more-exceptions to main February 5, 2025 08:46
@eikes
Copy link
Collaborator Author

eikes commented Feb 11, 2025

@phylor Thank you for working on this! I am fine with the changes as they are now. Please feel free to merge this.

@eikes eikes changed the title Update faraday to 2.9, remove deprecated faraday_middleware gem Update faraday to 2.12, remove deprecated faraday_middleware gem Feb 11, 2025
@phylor phylor merged commit 771e650 into main Feb 11, 2025
2 checks passed
@phylor phylor deleted the update-faraday-2-9 branch February 11, 2025 16:11
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.

2 participants