profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
506 stars 85 forks source link

Don't close user-provided requests sessions #232

Closed reconman closed 1 year ago

reconman commented 1 year ago

Description

If the user has provided a requests session in the RequestsEndpoint constructor, it will not be closed after each request anymore.

If no session was provided, one will be created in the constructor and closed in the destructor.

Related Issues

Closes #225

Pull request checklist

How to test it

Change the Github Agile Dashboard example the following way

  1. Replace the HTTPEndpoint with a RequestsEndpoint
  2. Enable debug logging, especially for the urllib3.connectionpool logger
  3. Check the log for "Starting new HTTPS connection" - it should only appear once
barbieri commented 1 year ago

failing tests checks the string serialization without session. Since these will be the case now (every call will have a session), just change the test at https://github.com/profusion/sgqlc/blob/master/tests/test-endpoint-requests.py

reconman commented 1 year ago

failing tests checks the string serialization without session. Since these will be the case now (every call will have a session), just change the test at https://github.com/profusion/sgqlc/blob/master/tests/test-endpoint-requests.py

Tried to execute the test on windows, but it horrible fails in the initialization:

Traceback (most recent call last):
  File "C:\Github\sgqlc\setup.py", line 23, in <module>
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\__init__.py", line 87, in setup
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\_distutils\dist.py", line 968, in run_commands
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\dist.py", line 1217, in run_command
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\_distutils\dist.py", line 987, in run_command
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\commands.py", line 158, in run
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\core.py", line 118, in __init__
  File "C:\Program Files\Python311\Lib\unittest\main.py", line 101, in __init__
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\core.py", line 145, in parseArgs
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\config.py", line 346, in configure
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\plugins\manager.py", line 284, in configure
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\plugins\manager.py", line 99, in __call__
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\plugins\manager.py", line 167, in simple
  File "C:\Github\sgqlc\venv\Lib\site-packages\nose\plugins\cover.py", line 156, in configure
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 565, in start
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\collector.py", line 329, in start
  File "C:\Program Files\Python311\Lib\threading.py", line 72, in settrace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1534, in _shutdown
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in atexit callback: <bound method Coverage._atexit of <coverage.control.Coverage object at 0x0000020C17043250>>
Traceback (most recent call last):
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 578, in _atexit
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in atexit callback: <function shutdown at 0x0000020C1440BD80>
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\logging\__init__.py", line 2177, in shutdown
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in: <function Forward.__del__ at 0x0000020C16024360>
Traceback (most recent call last):
  File "C:\Github\sgqlc\venv\Lib\site-packages\setuptools\_vendor\pyparsing\core.py", line 5186, in __del__
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in: <function Forward.__del__ at 0x0000020C15C9A980>
Traceback (most recent call last):
  File "C:\Github\sgqlc\venv\Lib\site-packages\pkg_resources\_vendor\pyparsing\core.py", line 5186, in __del__
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Exception ignored in: <function _removeHandlerRef at 0x0000020C14403B00>
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\logging\__init__.py", line 845, in _removeHandlerRef
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\control.py", line 334, in _should_trace
  File "C:\Github\sgqlc\venv\Lib\site-packages\coverage\inorout.py", line 321, in should_trace
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

So I'll have to rely on Github actions to check if the tests are fixed.

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 5315290371


Totals Coverage Status
Change from base Build 5192762666: 0.0%
Covered Lines: 1599
Relevant Lines: 1599

💛 - Coveralls
barbieri commented 1 year ago

thanks