Make ClientConnectorCertificateError.ssl mean the same as on the base class - #13583
Make ClientConnectorCertificateError.ssl mean the same as on the base class#13583ArockiaRajamanickam wants to merge 1 commit into
ClientConnectorCertificateError.ssl mean the same as on the base class#13583Conversation
… class ConnectionKey carries both is_ssl, a bool, and ssl, the SSLContext, bool or Fingerprint the caller passed. They sit on adjacent lines. ClientConnectorError.ssl returns ssl; ClientConnectorCertificateError overrode it to return is_ssl, so catching the subclass gave a plain bool where the base gave back the caller's own SSLContext. Dropping the override lets the subclass inherit, and __str__ now renders ssl is True as 'default', as the base class already did. Closes aio-libs#4099
Confidence Score: 4/5The implementation appears safe to merge, with a non-blocking requirement to document the changed public attribute contract in the client reference documentation. The exception now consistently exposes Files Needing Attention: aiohttp/client_exceptions.py and the relevant client reference documentation Reviews (1): Last reviewed commit: "Make ClientConnectorCertificateError.ssl..." | Re-trigger Greptile |
| def ssl(self) -> bool: | ||
| return self._conn_key.is_ssl | ||
|
|
||
| def __str__(self) -> str: |
There was a problem hiding this comment.
Removing this override changes ClientConnectorCertificateError.ssl from a boolean to the inherited SSLContext | bool | Fingerprint contract, but no client reference documentation explains the new contract or migration from the former boolean meaning. The repository requires user-visible API changes to be reflected under docs/, rather than only in a changelog fragment.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13583 +/- ##
=======================================
Coverage 99.02% 99.02%
=======================================
Files 135 135
Lines 50500 50506 +6
Branches 2652 2652
=======================================
+ Hits 50007 50013 +6
Misses 370 370
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
What do these changes do?
Closes #4099.
ConnectionKeycarries two adjacent fields:ClientConnectorError.sslreturnsssl.ClientConnectorCertificateErroroverrode it to returnis_ssl, so the same attribute on the same connection key meant two different things depending on which exception you caught:The override is dropped so the subclass inherits from
ClientConnectorError, which is where the attribute is already correct.__str__now rendersssl is Trueasdefaultthe way the base class does, instead of printingTrue.@asvetlov confirmed this back in 2019 ("I think yes. The result of the project evolvement."). This follows the same reasoning as #12136, which restored
os_erroron this class on Liskov grounds six months ago.Are there changes in behavior for the user?
Yes, and this is the part worth reviewing carefully.
Anyone reading
.sslonClientConnectorCertificateErroras a boolean now gets whatever was passed tossl=, which for the default case isTruebut for a configured client is anSSLContextor aFingerprint. Code wanting the old boolean should readis_sslfrom the connection key. I filed the fragment asbreakingrather thanbugfixfor that reason, andmasterbeing4.0.0a2.dev0seemed like the right window to correct it.__str__also changes for thessl=Truecase, fromssl:Truetossl:default, which is whatClientConnectorErroralready prints.Three existing assertions had to be flipped, and I want to flag that rather than have it found in review:
Those assertions encoded the behaviour being fixed. I would normally treat "the fix requires changing existing tests" as a sign the behaviour is intended, and I checked that here rather than assuming: the issue carries the
buglabel and a maintainer said plainly that it is one. If that reading is wrong, this should be closed rather than merged.Also for transparency: the issue is assigned to @asvetlov, from 2019. Nothing has moved on it since, so I took it as open rather than in hand. Happy to close if that is not right.
The redundant
hostandportoverrides on the same class are identical to the base class implementations. I left them alone to keep this diff to the bug.Is it a substantial burden for the maintainers to support this?
No. The class now inherits three properties instead of overriding two of them incorrectly.
Testing
test_ssl_is_the_same_as_on_the_base_classbuilds both exceptions from oneConnectionKeyholding a realSSLContextand assertserr.ssl is contextanderr.ssl is base_err.ssl, sois_sslandsslcannot be confused by both happening to beTrue.Reverting only
client_exceptions.pyand keeping the tests fails 4 tests inTestClientConnectorCertificateError, including the new one.tests/test_client_exceptions.pyis 29 passed / 1 xfailed, andtest_client_exceptions.pyplustest_client_functional.pytogether are 318 passed / 27 skipped / 2 xfailed.ruff checkreports the same 6 pre-existing findings on these files asmasterdoes, none from this change.Checklist
CHANGES/folderCONTRIBUTORS.txtI used an AI assistant while working on this. The reproduction, the check on whether the flipped assertions were load-bearing, and the decision to file this as
breakingrather thanbugfixare mine, and I ran every result quoted here.