Skip to content

fix: resolve 'bytes' object has no attribute 'decoded' for large CODEOWNERS files#379

Merged
jmeridth merged 1 commit intomainfrom
fix/large-codeowners-bytes-attribute-error
Apr 7, 2026
Merged

fix: resolve 'bytes' object has no attribute 'decoded' for large CODEOWNERS files#379
jmeridth merged 1 commit intomainfrom
fix/large-codeowners-bytes-attribute-error

Conversation

@jmeridth
Copy link
Copy Markdown
Collaborator

@jmeridth jmeridth commented Apr 7, 2026

Pull Request

Proposed Changes

Fixes #378

What

Normalize CODEOWNERS file contents to bytes before processing, so both the normal path (Contents object with .decoded) and the large-file path (raw bytes from blob().decode_content()) use the same type downstream.

Why

When a CODEOWNERS file is large enough that the GitHub API returns null content, the code fetches it via blob().decode_content() which returns raw bytes. The code then called .decoded on that bytes object, crashing with 'bytes' object has no attribute 'decoded' and preventing PR creation for user removal.

Notes

  • The isinstance check in get_usernames_from_codeowners handles both bytes lines and str lines, since the function now accepts raw bytes or str directly
  • Existing tests updated to pass bytes/str directly instead of mocking .decoded, matching the new contract

Testing

  • Added regression test test_get_usernames_from_codeowners_with_raw_bytes that passes raw bytes (simulating the large file path) and verifies usernames are extracted correctly
  • Updated existing tests to pass bytes/str directly to get_usernames_from_codeowners instead of using a mock with .decoded
  • All 63 tests pass with 96% coverage

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

…OWNERS files

Fixes #378

## What

Normalize CODEOWNERS file contents to bytes before processing, so both
the normal path (Contents object with .decoded) and the large-file path
(raw bytes from blob().decode_content()) use the same type downstream.

## Why

When a CODEOWNERS file is large enough that the GitHub API returns null
content, the code fetches it via blob().decode_content() which returns
raw bytes. The code then called .decoded on that bytes object, crashing
with "'bytes' object has no attribute 'decoded'" and preventing PR
creation for user removal.

## Notes

- The isinstance check in get_usernames_from_codeowners handles both bytes lines and str lines, since the function now accepts raw bytes or str directly
- Existing tests updated to pass bytes/str directly instead of mocking .decoded, matching the new contract

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth added the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Apr 7, 2026
@jmeridth jmeridth self-assigned this Apr 7, 2026
@jmeridth jmeridth added the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Apr 7, 2026
@github-actions github-actions bot added the fix label Apr 7, 2026
@github-actions github-actions bot marked this pull request as ready for review April 7, 2026 15:53
@github-actions github-actions bot requested a review from zkoppert as a code owner April 7, 2026 15:53
@github-actions github-actions bot removed the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Apr 7, 2026
Copy link
Copy Markdown
Collaborator

@zkoppert zkoppert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - the normalization to codeowners_decoded handles both paths cleanly, and the isinstance check in get_usernames_from_codeowners is a good move for handling both bytes and str. The regression test covers the new code path well. 🚀

@jmeridth jmeridth merged commit 7e3e6a8 into main Apr 7, 2026
36 of 39 checks passed
@jmeridth jmeridth deleted the fix/large-codeowners-bytes-attribute-error branch April 7, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: 'bytes' object has no attribute 'decoded'

2 participants