Skip to content

DiffEntry has no sha when permission changes #196

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
jayjoshi64 opened this issue Mar 17, 2025 · 2 comments · Fixed by #197
Closed

DiffEntry has no sha when permission changes #196

jayjoshi64 opened this issue Mar 17, 2025 · 2 comments · Fixed by #197
Labels
bug Something isn't working Rest API schema schema related

Comments

@jayjoshi64
Copy link

jayjoshi64 commented Mar 17, 2025

Reproduce steps:

  1. Create a commit which has permission changed. No changes in the file content.
  2. Try to get the commit using compare_commits
github.rest.repos.compare_commits(
    owner="test",
    repo=""test,
    basehead="abcabcabcabc~1...abcabcabcabc"
).parsed_data

Fails with

--->  ).parsed_data
File [/usr/local/lib/python3.10/site-packages/githubkit/response.py:94](githubkit/response.py:94), in Response.parsed_data(self)
     [92](githubkit/response.py:92) @property
     [93](githubkit/response.py:93) def parsed_data(self) -> MT:
---> [94](githubkit/response.py:94)     return type_validate_json(self._data_model, self.content)

File [/usr/local/lib/python3.10/site-packages/githubkit/compat.py:43](githubkit/compat.py:43), in type_validate_json(type_, data)
     [42](githubkit/compat.py:42) def type_validate_json(type_: type[T], data: Any) -> T:
---> [43](githubkit/compat.py:43)     return TypeAdapter(type_).validate_json(data)

File [/usr/local/lib/python3.10/site-packages/pydantic/type_adapter.py:135](pydantic/type_adapter.py:135), in _frame_depth.<locals>.wrapper.<locals>.wrapped(self, *args, **kwargs)
    [132](pydantic/type_adapter.py:132) @wraps(func)
    [133](pydantic/type_adapter.py:133) def wrapped(self: TypeAdapterT, *args: P.args, **kwargs: P.kwargs) -> R:
    [134](pydantic/type_adapter.py:134)     with self._with_frame_depth(depth + 1):  # depth + 1 for the wrapper function
--> [135](pydantic/type_adapter.py:135)         return func(self, *args, **kwargs)

File [/usr/local/lib/python3.10/site-packages/pydantic/type_adapter.py:384](pydantic/type_adapter.py:384), in TypeAdapter.validate_json(self, data, strict, context)
    [368](pydantic/type_adapter.py:368) @_frame_depth(1)
    [369](pydantic/type_adapter.py:369) def validate_json(
    [370](pydantic/type_adapter.py:370)     self, data: str | bytes, [/](None = None, context: dict[str, Any] | None = None
    [371](pydantic/type_adapter.py:371) ) -> T:
    [372](pydantic/type_adapter.py:372)     """Usage docs: https://docs.pydantic.dev/2.9/concepts/json/#json-parsing
    [373](pydantic/type_adapter.py:373) 
    [374](pydantic/type_adapter.py:374)     Validate a JSON string or bytes against the model.
   (...)
    [382](pydantic/type_adapter.py:382)         The validated object.
    [383](pydantic/type_adapter.py:383)     """
--> [384](pydantic/type_adapter.py:384)     return self.validator.validate_json(data, strict=strict, context=context)

ValidationError: 2 validation errors for CommitComparison
files.literal[<UNSET>]
  Input should be <UNSET> [type=literal_error, input_value=[{'sha': 'abcabcabc...'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.9/v/literal_error
files.list[DiffEntry].2.sha
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.9/v/string_type

Tha main changes in the endpoint is that there's no SHA for the file change:

{'sha': None,     <--- This is the issue
   'filename': 'test.py',
   'status': 'modified',
   'additions': 0,
   'deletions': 0,
   'changes': 0,
   'blob_url': '. . .',
   'raw_url': '. . .',
   'contents_url': '. . .'
}
@yanyongyu yanyongyu added bug Something isn't working schema schema related Rest API labels Mar 18, 2025
@yanyongyu
Copy link
Owner

The diff-entry object's sha field can be None. Could you please also report this to https://github.com/github/rest-api-description/? I will make a schema patch to fix this in githubkit.

@jayjoshi64
Copy link
Author

created: github/rest-api-description#4652

@yanyongyu , I am new to rest-api-description. Feel free to add any details that I missed, thanks.

@yanyongyu yanyongyu changed the title Any commit with permission changes breaks compare_commits DiffEntry has no sha when permission changes Mar 22, 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