Description
The generated model WebhookCodeScanningAlertFixedPropAlert (in githubkit/versions/v2022_11_28/models/group_0546.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: "fixed", the alert.fixed_at field contains an ISO 8601 datetime string (e.g. "2025-06-15T10:30:00Z"), which causes a Pydantic ValidationError.
Expected
fixed_at should be typed as Missing[Union[datetime, None]] (or equivalently Missing[Optional[datetime]]), consistent with how created_at and dismissed_at are typed on the same model.
Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for code_scanning_alert (action fixed) defines fixed_at with only type: null.
I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6058
Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs. 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), and the core schema generator reads model_fields. The parent model must also be rebuilt so its compiled Pydantic-core validator picks up the new child schema:
from datetime import datetime
from githubkit.typing import Missing
from githubkit.versions.latest.models import (
WebhookCodeScanningAlertFixed,
WebhookCodeScanningAlertFixedPropAlert,
)
_FIXED_AT_TYPE = Missing[datetime]
WebhookCodeScanningAlertFixedPropAlert.__annotations__["fixed_at"] = _FIXED_AT_TYPE
WebhookCodeScanningAlertFixedPropAlert.model_fields["fixed_at"].annotation = _FIXED_AT_TYPE
WebhookCodeScanningAlertFixedPropAlert.model_rebuild(force=True)
WebhookCodeScanningAlertFixed.model_rebuild(force=True)
Note: patching only model_fields (without __annotations__) does not work — model_rebuild(force=True) re-resolves from the string annotation and overwrites the change.
Environment
- githubkit version: 0.14.5
- Python: 3.12
- Pydantic: v2
Description
The generated model
WebhookCodeScanningAlertFixedPropAlert(ingithubkit/versions/v2022_11_28/models/group_0546.py) defines thefixed_atfield as:This means the field can only be
UNSETorNone. However, when GitHub delivers acode_scanning_alertwebhook withaction: "fixed", thealert.fixed_atfield contains an ISO 8601 datetime string (e.g."2025-06-15T10:30:00Z"), which causes a PydanticValidationError.Expected
fixed_atshould be typed asMissing[Union[datetime, None]](or equivalentlyMissing[Optional[datetime]]), consistent with howcreated_atanddismissed_atare typed on the same model.Root Cause
This is an upstream issue in the GitHub REST API OpenAPI description. The webhook schema for
code_scanning_alert(actionfixed) definesfixed_atwith onlytype: null.I've filed a Schema Inaccuracy issue upstream: github/rest-api-description#6058
Workaround
A runtime monkey-patch can be applied before any webhook parsing occurs. Both
__annotations__andmodel_fieldsmust be patched because the source usesfrom __future__ import annotations(somodel_rebuildre-resolves from the string annotation), and the core schema generator readsmodel_fields. The parent model must also be rebuilt so its compiled Pydantic-core validator picks up the new child schema:Note: patching only
model_fields(without__annotations__) does not work —model_rebuild(force=True)re-resolves from the string annotation and overwrites the change.Environment