Skip to content

fix: work around asyncssh/fido2 AttributeError on Python 3.14 non-Windows#23

Merged
gensyn merged 3 commits into
mainfrom
copilot/fix-attributeerror-ctypes-hresult
Apr 19, 2026
Merged

fix: work around asyncssh/fido2 AttributeError on Python 3.14 non-Windows#23
gensyn merged 3 commits into
mainfrom
copilot/fix-attributeerror-ctypes-hresult

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

On Python 3.14, ctypes.HRESULT was removed for non-Windows platforms. When fido2 is installed in the HA environment, asyncssh's sk.py attempts from fido2.client.windows import WindowsClient inside a try/except ImportError block — but fido2/client/win_api.py raises AttributeError at module level (HRESULT = ctypes.HRESULT), which goes uncaught and blows up the entire asyncssh import.

Fix

Pre-attempt the problematic import in coordinator.py before asyncssh is loaded. On failure, write None into sys.modules["fido2.client.windows"] — Python's negative-cache mechanism — so that asyncssh's subsequent import attempt raises ImportError instead, which it already handles gracefully (disabling Windows WebAuthn support).

if sys.platform != "win32":
    try:
        import fido2.client.windows  # noqa: F401
    except (ImportError, OSError, AttributeError) as _fido2_err:
        _LOGGER.debug(
            "fido2.client.windows unavailable (%s); asyncssh Windows WebAuthn support disabled",
            _fido2_err,
        )
        sys.modules["fido2.client.windows"] = None

This is a targeted workaround for a bug in asyncssh's exception handling (except ImportError should be except (ImportError, AttributeError)). No functional behaviour changes on Windows or in environments where fido2 is absent or fully compatible.

Copilot AI changed the title [WIP] Fix AttributeError in SSH Command integration on Python 3.14 fix: work around asyncssh/fido2 AttributeError on Python 3.14 non-Windows Apr 18, 2026
Copilot AI requested a review from gensyn April 18, 2026 20:33
@gensyn gensyn marked this pull request as ready for review April 19, 2026 11:29
Copilot AI review requested due to automatic review settings April 19, 2026 11:29
@gensyn gensyn merged commit 4b98388 into main Apr 19, 2026
6 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Works around a Python 3.14 import-time crash involving asyncssh and fido2 on non-Windows platforms by pre-handling the problematic fido2.client.windows import before asyncssh is imported.

Changes:

  • Adds an early, non-Windows-only pre-import of fido2.client.windows and on failure seeds sys.modules["fido2.client.windows"] = None so later imports raise ImportError instead of AttributeError.
  • Moves _LOGGER initialization earlier to support debug logging during the pre-import step.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread coordinator.py
Comment on lines +28 to +30
try:
import fido2.client.windows # noqa: F401
except (ImportError, OSError, AttributeError) as _fido2_err:
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# noqa: F401 won’t silence pylint’s unused-import check (and the workflow doesn’t disable unused-import), so this line is likely to fail CI. Prefer a pylint suppression (# pylint: disable=unused-import) or avoid binding an unused name by using importlib.import_module("fido2.client.windows") instead of a plain import.

Copilot uses AI. Check for mistakes.
Comment thread coordinator.py
Comment on lines +27 to +35
if sys.platform != "win32":
try:
import fido2.client.windows # noqa: F401
except (ImportError, OSError, AttributeError) as _fido2_err:
_LOGGER.debug(
"fido2.client.windows unavailable (%s); asyncssh Windows WebAuthn support disabled",
_fido2_err,
)
sys.modules["fido2.client.windows"] = None # type: ignore[assignment]
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workaround changes module import-time behavior on non-Windows by mutating sys.modules. There’s currently no unit test covering the failure path (e.g., simulating fido2.client.windows raising AttributeError) to ensure coordinator.py still imports and the negative-cache entry is installed; adding one would help prevent regressions on Python 3.14+.

Copilot uses AI. Check for mistakes.
@gensyn gensyn deleted the copilot/fix-attributeerror-ctypes-hresult branch April 19, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: module 'ctypes' has no attribute 'HRESULT' on Python 3.14

3 participants