Skip to content

fix: make X-Glean hook resilient to SDK regeneration#107

Merged
chris-freeman-glean merged 1 commit intomainfrom
cfreeman/fix-sdkconfiguration-genignore
Feb 3, 2026
Merged

fix: make X-Glean hook resilient to SDK regeneration#107
chris-freeman-glean merged 1 commit intomainfrom
cfreeman/fix-sdkconfiguration-genignore

Conversation

@chris-freeman-glean
Copy link
Contributor

Summary

  • Use getattr() with defaults instead of direct attribute access for exclude_deprecated_after and include_experimental config fields
  • Fixes mypy errors that occur after Speakeasy regenerates sdkconfiguration.py

Background

PR #106 added custom fields to sdkconfiguration.py for X-Glean header support. However, Speakeasy regenerates this file daily, removing the custom fields. The hook (x_glean.py) survives regeneration but then references non-existent attributes, causing mypy failures:

src/glean/api_client/_hooks/x_glean.py:52: error: "SDKConfiguration" has no attribute "exclude_deprecated_after"
src/glean/api_client/_hooks/x_glean.py:57: error: "SDKConfiguration" has no attribute "include_experimental"

This has been breaking the Generate CI workflow since Jan 27th.

Solution

Replace direct attribute access with getattr() calls that return None when the attribute doesn't exist:

# Before
hook_ctx.config.exclude_deprecated_after
hook_ctx.config.include_experimental

# After  
getattr(hook_ctx.config, "exclude_deprecated_after", None)
getattr(hook_ctx.config, "include_experimental", None)

Verification

  • ✅ Ran actual speakeasy run which regenerated sdkconfiguration.py without custom attributes
  • ✅ mypy passes after regeneration
  • ✅ All 14 hook tests pass after regeneration
  • ✅ Environment variables continue to work (they take precedence anyway)

Test plan

  • Run mypy: poetry run python -m mypy src/glean/api_client
  • Run hook tests: poetry run pytest tests/test_x_glean_hook.py -v
  • Run actual Speakeasy generation and verify mypy still passes

🤖 Generated with Claude Code

Use getattr() with defaults instead of direct attribute access for
exclude_deprecated_after and include_experimental config fields.

This fixes mypy errors that occur after Speakeasy regenerates
sdkconfiguration.py, which removes the custom fields added in PR #106.

The hook now gracefully handles missing attributes while still
supporting environment variables (which take precedence anyway).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@chris-freeman-glean chris-freeman-glean marked this pull request as ready for review February 3, 2026 17:21
@chris-freeman-glean chris-freeman-glean requested a review from a team as a code owner February 3, 2026 17:21
@chris-freeman-glean chris-freeman-glean merged commit 18690c2 into main Feb 3, 2026
3 checks passed
@chris-freeman-glean chris-freeman-glean deleted the cfreeman/fix-sdkconfiguration-genignore branch February 3, 2026 17:56
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.

1 participant