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

Failing tests with responses ≥ 0.22.0 #1461

Closed
2 tasks done
alexshpilkin opened this issue Dec 25, 2022 · 1 comment
Closed
2 tasks done

Failing tests with responses ≥ 0.22.0 #1461

alexshpilkin opened this issue Dec 25, 2022 · 1 comment
Labels
bug Something isn't working new Needs triage. Comments are welcome!

Comments

@alexshpilkin
Copy link

alexshpilkin commented Dec 25, 2022

Checklist

  • I've searched for similar issues.
  • I'm using the latest version of HTTPie.

Minimal reproduction code and steps

  1. git clone https://github.com/httpie/httpie; cd httpie
  2. pip install 'responses>=0.22.0' .[test]
  3. pytest

Current result

A multitude of failures in tests/test_encoding.py, tests/test_json.py, etc. in the vein of https://hydra.nixos.org/build/202035507: KeyError: 0 on httpie/models.py line 82.

Expected result

A passing test suite.


Additional information, screenshots, or code examples

I wrote some of this up in NixOS/nixpkgs#205270 (comment), but the problem is not NixOS-specific. The short version is that before getsentry/responses#585, the reference to httpie.models.HTTPResponse()._orig.raw._original_response.version in the implementation of httpie.models.HTTPResponse.headers found the then-extant responses.OriginalResponseShim object, which does not have a version attribute, and therefore successfully defaulted to 11, whereas now that that class has been removed it finds a urllib3.HTTPResponse object instead, which defaults to version=0, and it’s not prepared to handle that.

Given the amount of groveling into internal data structures that goes on here (I don’t think requests even documents Request.raw as being a urllib3.HTTPResponse object), I’m not sure if this is a bug in the httpie test suite or a regression in responses, so I’m filing it here for you to decide.

For reference, the following change makes the tests pass for me:

diff --git a/httpie/models.py b/httpie/models.py
index d97b55e..a3ec6e7 100644
--- a/httpie/models.py
+++ b/httpie/models.py
@@ -77,6 +77,8 @@ class HTTPResponse(HTTPMessage):
             else:
                 raw_version = raw.version
         except AttributeError:
+            raw_version = 0
+        if not raw_version:
             # Assume HTTP/1.1
             raw_version = 11
         version = {
@alexshpilkin alexshpilkin added bug Something isn't working new Needs triage. Comments are welcome! labels Dec 25, 2022
@alexshpilkin alexshpilkin changed the title Failing tests with responses ≥ 0.2.2 Failing tests with responses ≥ 0.22.0 Dec 25, 2022
@jkbrzt jkbrzt closed this as completed in e73c3e6 Jan 15, 2023
@jkbrzt
Copy link
Member

jkbrzt commented Jan 15, 2023

@alexshpilkin thank you for the detailed report! Fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Needs triage. Comments are welcome!
Projects
None yet
Development

No branches or pull requests

2 participants