Skip to content

[FIX] Resolve ContentFile subscript TypeError when fetching issue template (#1261) - #1262

Open
garv-sanveria wants to merge 1 commit into
CCExtractor:masterfrom
garv-sanveria:fix/upload-contentfile-subscript
Open

garv-sanveria wants to merge 1 commit into
CCExtractor:masterfrom
garv-sanveria:fix/upload-contentfile-subscript

Conversation

@garv-sanveria

@garv-sanveria garv-sanveria commented Nov 5, 2026 •

Copy link
Copy Markdown

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Summary

Fixes #1261

When a user completes a sample upload with the option to report an issue to GitHub (form.report.data == 'y'), mod_upload/controllers.py fetches the repository issue template via repository.get_contents(".github/ISSUE_TEMPLATE.md").

Since migrating to PyGithub, get_contents() returns a github.ContentFile.ContentFile object rather than a dictionary. Subscripting response['content'] and response['encoding'] raises:

TypeError: 'ContentFile' object is not subscriptable

This causes an unhandled 500 Internal Server Error, preventing the issue from being created on GitHub and failing the upload redirection.

Changes

  1. mod_upload/controllers.py: Used response.decoded_content.decode('utf-8') provided by PyGithub's ContentFile to decode the template string directly instead of indexing into the object and running manual base64 decoding.
  2. tests/test_upload/test_controllers.py: Updated test_process to mock get_contents with an actual ContentFile instance containing decoded_content rather than a plain dictionary, preventing mock-reality drift and protecting against future regressions.

Testing & Verification

  • Ran pytest tests/test_upload/test_controllers.py (all 12 tests passed).
  • Verified with code quality tools: pycodestyle, isort, pydocstyle, and mypy.

@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] TypeError: 'ContentFile' object is not subscriptable in mod_upload when creating GitHub issue

1 participant