Skip to content

Commit 10de4bd

Browse files
committed
Fix AttributeError: 'ClientConnectorCertificateError' object has no attribute '_os_error'.
ClientConnectorCertificateError is a subclass of ClientConnectorError and should have all of its attributes (LSP). However, when I try to access the os_error attribute, I get the mentioned exception.
1 parent 4ec897b commit 10de4bd

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

CHANGES/12136.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``ClientConnectorCertificateError.os_error`` no longer raises :exc:`AttributeError`
2+
-- by :user:`themylogin`.

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ Vladimir Kamarzin
392392
Vladimir Kozlovski
393393
Vladimir Rutsky
394394
Vladimir Shulyak
395+
Vladimir Vinogradenko
395396
Vladimir Zakharov
396397
Vladyslav Bohaichuk
397398
Vladyslav Bondar

aiohttp/client_exceptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,12 @@ class ClientConnectorSSLError(*ssl_error_bases): # type: ignore[misc]
342342
class ClientConnectorCertificateError(*cert_errors_bases): # type: ignore[misc]
343343
"""Response certificate error."""
344344

345+
_conn_key: ConnectionKey
346+
345347
def __init__(
346348
self, connection_key: ConnectionKey, certificate_error: Exception
347349
) -> None:
348-
self._conn_key = connection_key
350+
super().__init__(connection_key, OSError())
349351
self._certificate_error = certificate_error
350352
self.args = (connection_key, certificate_error)
351353

tests/test_client_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ def test_str(self) -> None:
201201
" [Exception: ('Bad certificate',)]"
202202
)
203203

204+
def test_oserror(self) -> None:
205+
certificate_error = Exception("Bad certificate")
206+
err = client.ClientConnectorCertificateError(
207+
connection_key=self.connection_key, certificate_error=certificate_error
208+
)
209+
assert err.os_error == OSError()
210+
204211

205212
class TestServerDisconnectedError:
206213
def test_ctor(self) -> None:

0 commit comments

Comments
 (0)