Skip to content

Issue.state_reason can now be duplicate #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sterliakov opened this issue Feb 2, 2025 · 1 comment · Fixed by #192
Closed

Issue.state_reason can now be duplicate #188

sterliakov opened this issue Feb 2, 2025 · 1 comment · Fixed by #192
Labels
bug Something isn't working Rest API schema schema related

Comments

@sterliakov
Copy link

Cross-ref to https://github.com/orgs/community/discussions/150535.

I'm not sure if there is anything to do on the library side, but other users are likely to search for the problem here. API docs do not list "duplicate" as a valid value for Issue.state_reason, but it does not prevent their API from returning such.

In the meantime, the following patch allows arbitrary close_reason values:

def _patch_issue_model():
    """Patch API bug. https://github.com/orgs/community/discussions/150535"""
    from githubkit.typing import Missing
    Issue.model_fields['state_reason'].annotation = Missing[str | None]
    Issue.model_rebuild(force=True)


_patch_issue_model()

My traceback for better indexing:

Traceback (most recent call last):
  File "/home/runner/work/mypy-issues/mypy-issues/.venv/bin/fetch", line 10, in <module>
    sys.exit(fetch_issues())
             ~~~~~~~~~~~~^^
  File "/home/runner/work/mypy-issues/mypy-issues/src/mypy_issues/__init__.py", line 28, in fetch_issues
    download_snippets(token, limit=args.limit)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/mypy-issues/mypy-issues/src/mypy_issues/issues.py", line 47, in download_snippets
    removed = {iss.number for iss in _get_closed_issues(gh, org, repo, since)}
                                     ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/mypy-issues/mypy-issues/src/mypy_issues/issues.py", line 147, in _get_closed_issues
    ).parsed_data
      ^^^^^^^^^^^
  File "/home/runner/work/mypy-issues/mypy-issues/.venv/lib/python3.13/site-packages/githubkit/response.py", line 94, in parsed_data
    return type_validate_json(self._data_model, self.content)
  File "/home/runner/work/mypy-issues/mypy-issues/.venv/lib/python3.13/site-packages/githubkit/compat.py", line 43, in type_validate_json
    return TypeAdapter(type_).validate_json(data)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/runner/work/mypy-issues/mypy-issues/.venv/lib/python3.13/site-packages/pydantic/type_adapter.py", line 446, in validate_json
    return self.validator.validate_json(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        data, strict=strict, context=context, allow_partial=experimental_allow_partial
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
pydantic_core._pydantic_core.ValidationError: 2 validation errors for list[Issue]
0.state_reason.literal[<UNSET>]
  Input should be <UNSET> [type=literal_error, input_value='duplicate', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/literal_error
0.state_reason.literal['completed','reopened','not_planned']
  Input should be 'completed', 'reopened' or 'not_planned' [type=literal_error, input_value='duplicate', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/literal_error

Please keep this open until the upstream issue is resolved.

@yanyongyu
Copy link
Owner

Maybe you could report this bug to https://github.com/github/rest-api-description . githubkit can also create a schema patch to fix this temporarily.

@yanyongyu yanyongyu added bug Something isn't working schema schema related Rest API labels Feb 3, 2025
@yanyongyu yanyongyu changed the title Issue.state_reason can now be duplicate? Issue.state_reason can now be duplicate Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Rest API schema schema related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants