Description
The generated model WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy (in githubkit/versions/v2022_11_28/models/) is an empty Pydantic model with zero fields:
class WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy(GitHubModel):
"""WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy"""
Because GitHubModel uses Pydantic v2's default extra="ignore", when GitHub sends a full user object ({"login": "octocat", "id": 1, ...}) as dismissed_by, all fields are silently dropped. The model instantiates successfully but contains no data. Any subsequent access to .login raises AttributeError.
The dismissed_by field on WebhookCodeScanningAlertReopenedPropAlert is typed as:
dismissed_by: Union[WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy, None]
Every other action variant's DismissedBy type has the full simple-user schema (login, id, avatar_url, etc.) — only reopened has this empty model.
Expected
WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy should have the same fields as the other action variants (e.g. WebhookCodeScanningAlertAppearedInBranchPropAlertPropDismissedBy), which correctly reference the simple-user schema.
Alternatively, dismissed_by on WebhookCodeScanningAlertReopenedPropAlert could directly reference a shared user type rather than a dedicated empty model.
Error
AttributeError: 'WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy' object has no attribute 'login'
Triggered at runtime when accessing alert.dismissed_by.login after a code_scanning_alert reopened webhook fires for a previously-dismissed alert.
Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for code_scanning_alert (action reopened) defines dismissed_by as an empty object {} with no properties instead of referencing simple-user. I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6107
Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs, following the same pattern as #275 and #279:
from typing import Union
from githubkit.versions.latest.models import (
WebhookCodeScanningAlertAppearedInBranchPropAlertPropDismissedBy,
WebhookCodeScanningAlertReopened,
WebhookCodeScanningAlertReopenedPropAlert,
)
_DISMISSED_BY_TYPE = Union[WebhookCodeScanningAlertAppearedInBranchPropAlertPropDismissedBy, None]
WebhookCodeScanningAlertReopenedPropAlert.__annotations__["dismissed_by"] = _DISMISSED_BY_TYPE
WebhookCodeScanningAlertReopenedPropAlert.model_fields["dismissed_by"].annotation = _DISMISSED_BY_TYPE
WebhookCodeScanningAlertReopenedPropAlert.model_rebuild(force=True)
WebhookCodeScanningAlertReopened.model_rebuild(force=True)
Note: both __annotations__ and model_fields must be patched because the source uses from __future__ import annotations, so model_rebuild re-resolves from the string annotation. The parent model must also be rebuilt so its compiled Pydantic-core validator picks up the new child schema.
Environment
- githubkit version: 0.14.6
- Python: 3.12
- Pydantic: v2
Description
The generated model
WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy(ingithubkit/versions/v2022_11_28/models/) is an empty Pydantic model with zero fields:Because
GitHubModeluses Pydantic v2's defaultextra="ignore", when GitHub sends a full user object ({"login": "octocat", "id": 1, ...}) asdismissed_by, all fields are silently dropped. The model instantiates successfully but contains no data. Any subsequent access to.loginraisesAttributeError.The
dismissed_byfield onWebhookCodeScanningAlertReopenedPropAlertis typed as:Every other action variant's
DismissedBytype has the full simple-user schema (login,id,avatar_url, etc.) — onlyreopenedhas this empty model.Expected
WebhookCodeScanningAlertReopenedPropAlertPropDismissedByshould have the same fields as the other action variants (e.g.WebhookCodeScanningAlertAppearedInBranchPropAlertPropDismissedBy), which correctly reference thesimple-userschema.Alternatively,
dismissed_byonWebhookCodeScanningAlertReopenedPropAlertcould directly reference a shared user type rather than a dedicated empty model.Error
Triggered at runtime when accessing
alert.dismissed_by.loginafter acode_scanning_alertreopenedwebhook fires for a previously-dismissed alert.Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for
code_scanning_alert(actionreopened) definesdismissed_byas an empty object{}with no properties instead of referencingsimple-user. I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6107Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs, following the same pattern as #275 and #279:
Note: both
__annotations__andmodel_fieldsmust be patched because the source usesfrom __future__ import annotations, somodel_rebuildre-resolves from the string annotation. The parent model must also be rebuilt so its compiled Pydantic-core validator picks up the new child schema.Environment