Description
The generated model WebhookCodeScanningAlertClosedByUserPropAlert (in githubkit/versions/v2022_11_28/models/group_0542.py) defines the fixed_at field as:
fixed_at: Missing[None] = Field(
default=UNSET,
description="The time that the alert was fixed in ISO 8601 format: `YYYY-MM-DDTHH:MM:SSZ`.",
)
This means the field can only be UNSET or None. However, when GitHub delivers a code_scanning_alert webhook with action: "closed_by_user" for an alert that was previously auto-fixed, the alert.fixed_at field contains an ISO 8601 datetime string (e.g. "2026-03-04T17:53:59Z"), which causes a Pydantic ValidationError.
Expected
fixed_at should be typed as Missing[Union[datetime, None]] (or equivalently Missing[Optional[datetime]]), consistent with how it is already typed on WebhookCodeScanningAlertFixedPropAlert (fixed in PR #277).
Error
pydantic_core._pydantic_core.ValidationError: 1 validation error for
tagged-union[...,WebhookCodeScanningAlertClosedByUser,...]
closed_by_user.alert.fixed_at
Input should be <UNSET> [type=literal_error, input_value='2026-03-04T17:53:59Z', input_type=str]
Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for code_scanning_alert (action closed_by_user) defines fixed_at with only type: null. This is the same class of bug that was previously fixed for the fixed action in PR #277.
I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6081
Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs, following the same pattern as the fixed_at workaround in #275:
from datetime import datetime
from githubkit.typing import Missing
from githubkit.versions.latest.models import (
WebhookCodeScanningAlertClosedByUser,
WebhookCodeScanningAlertClosedByUserPropAlert,
)
_FIXED_AT_TYPE = Missing[datetime | None]
WebhookCodeScanningAlertClosedByUserPropAlert.__annotations__["fixed_at"] = _FIXED_AT_TYPE
WebhookCodeScanningAlertClosedByUserPropAlert.model_fields["fixed_at"].annotation = _FIXED_AT_TYPE
WebhookCodeScanningAlertClosedByUserPropAlert.model_rebuild(force=True)
WebhookCodeScanningAlertClosedByUser.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
WebhookCodeScanningAlertClosedByUserPropAlert(ingithubkit/versions/v2022_11_28/models/group_0542.py) defines thefixed_atfield as:This means the field can only be
UNSETorNone. However, when GitHub delivers acode_scanning_alertwebhook withaction: "closed_by_user"for an alert that was previously auto-fixed, thealert.fixed_atfield contains an ISO 8601 datetime string (e.g."2026-03-04T17:53:59Z"), which causes a PydanticValidationError.Expected
fixed_atshould be typed asMissing[Union[datetime, None]](or equivalentlyMissing[Optional[datetime]]), consistent with how it is already typed onWebhookCodeScanningAlertFixedPropAlert(fixed in PR #277).Error
Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for
code_scanning_alert(actionclosed_by_user) definesfixed_atwith onlytype: null. This is the same class of bug that was previously fixed for thefixedaction in PR #277.I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6081
Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs, following the same pattern as the
fixed_atworkaround in #275: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