Skip to content

WebhookCodeScanningAlertReopenedPropAlertPropDismissedBy has no fields — dismissed_by user data silently dropped #283

Description

@donicrosby

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    WebHookbugSomething isn't workingschemaschema related

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions