Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

RequestsHTTPTransport does not set headers on session like AIOHTTPTransport does

オープン 初心者向け
#613 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

gql.transport.requests.RequestsHTTPTransport と test/test_gql.py の再現コードから始め、セッションの動作を gql.transport.aiohttp.AIOHTTPTransport と比較します。Requests トランスポート用の対象テストを実行し、セッションヘッダーがコンストラクターのヘッダーと一致することを確認するとともに、既存のトランスポートテストが引き続きパスすることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug
When creating a transport = RequestsHTTPTransport with specific headers, transport.session.headers doesn't match what was given to the constructor (and is in transport.headers`)

This is at odd with the behaviour of AIOHTTPTransport, where we get transport.session.headers == transport.headers

To Reproduce
Steps to reproduce the behavior:

import pytest

from gql.transport.requests import RequestsHTTPTransport
from gql.transport.aiohttp import AIOHTTPTransport

@pytest.mark.asyncio
async def test_aio_http_transport_session():
    transport = AIOHTTPTransport("url", headers={"test": "header"})
    await transport.connect()
    assert transport.headers == transport.session.headers


def test_requests_http_transport_session():
    transport = RequestsHTTPTransport("url", headers={"test": "header"})
    transport.connect()
    assert transport.headers == transport.session.headers
$ uv run pytest -k test_gql -v                130 ↵   ✹ ✭ issue202/rest-client-headers
================================================= test session starts =================================================
platform linux -- Python 3.12.11, pytest-9.1.1, pluggy-1.6.0 -- /home/shtrom/work/simple-github/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/shtrom/work/simple-github
configfile: pyproject.toml
plugins: anyio-4.14.2, responses-0.6.0, aioresponses-0.3.0, mock-3.15.1, asyncio-1.4.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 34 items / 32 deselected / 2 selected

test/test_gql.py::test_aio_http_transport_session PASSED                                                        [ 50%]
test/test_gql.py::test_requests_http_transport_session FAILED                                                   [100%]

====================================================== FAILURES =======================================================
________________________________________ test_requests_http_transport_session _________________________________________

    def test_requests_http_transport_session():
        transport = RequestsHTTPTransport("url", headers={"test": "header"})
        transport.connect()
>       assert transport.headers == transport.session.headers
E       AssertionError: assert {'test': 'header'} == {'User-Agent'... 'keep-alive'}
E
E         Left contains 1 more item:
E         {'test': 'header'}
E         Right contains 4 more items:
E         {'Accept': '*/*',
E          'Accept-Encoding': 'gzip, deflate, br, zstd',
E          'Connection': 'keep-alive',...
E
E         ...Full output truncated (7 lines hidden), use '-vv' to show

test/test_gql.py:17: AssertionError
=============================================== short test summary info ===============================================
FAILED test/test_gql.py::test_requests_http_transport_session - AssertionError: assert {'test': 'header'} == {'User-Agent'... 'keep-alive'}
===================================== 1 failed, 1 passed, 32 deselected in 0.10s ======================================

Expected behavior
transport.session.headers == transport.headers for RequestHTTPTransport, same as AIOHTTPTransport already does.

System info (please complete the following information):

  • OS: Linux x86_64, Ubuntu 26.04
  • Python version: 3.14.4
  • gql version: 4.0
  • graphql-core version: 3.2.11
主要言語
Python
スター
1.7k
フォーク
195
平均マージ
14分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql-python/gql のほかの issue

graphql-python/gql の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。