diff --git a/CHANGES.rst b/CHANGES.rst index dfb8216e..85abe06d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Enhancements and Fixes ---------------------- +- Clear stale _ex before each execute_stream call [#751] + - Support VOTableFile in accessible_table and broadcast_samp [#745] - Declaratively define new-style standard IDs in Servicetype constraint [#744] diff --git a/pyvo/dal/query.py b/pyvo/dal/query.py index 72d0f3eb..d9caa06e 100644 --- a/pyvo/dal/query.py +++ b/pyvo/dal/query.py @@ -206,6 +206,7 @@ def execute_stream(self, *, post=False): No exceptions are raised here because non-2xx responses might still contain payload. They can be raised later by calling ``raise_if_error`` """ + self._ex = None response = self.submit(post=post) try: diff --git a/pyvo/dal/tests/test_query.py b/pyvo/dal/tests/test_query.py index 7a4b8bc9..4ad30282 100644 --- a/pyvo/dal/tests/test_query.py +++ b/pyvo/dal/tests/test_query.py @@ -302,6 +302,31 @@ def test_execute_raw(self): assert raw.startswith(b'') + def test_execute_stream_clears_stale_ex_on_success(self, mocker): + query = DALQuery('http://example.com/query/basic') + with mocker.register_uri('GET', '//example.com/query/basic', + text='Server Error', status_code=500): + query.execute_stream() + assert query._ex is not None + + with mocker.register_uri('GET', '//example.com/query/basic', + content=get_pkg_data_contents('data/query/basic.xml')): + query.execute_stream() + assert query._ex is None + + def test_execute_votable_raises_parse_error_not_stale_http_error(self, mocker): + query = DALQuery('http://example.com/query/basic') + with mocker.register_uri('GET', '//example.com/query/basic', + text='Server Error', status_code=500): + query.execute_stream() + assert query._ex is not None + + with mocker.register_uri('GET', '//example.com/query/basic', + content=b'not valid votable xml', + status_code=200): + with pytest.raises(DALFormatError): + query.execute_votable() + @pytest.mark.filterwarnings('ignore::astropy.io.votable.exceptions.W03') @pytest.mark.filterwarnings('ignore::astropy.io.votable.exceptions.W06')