feat(file): report a rejected file extension clearly on upload - #153
Open
LukasGold wants to merge 1 commit into
Open
feat(file): report a rejected file extension clearly on upload#153LukasGold wants to merge 1 commit into
LukasGold wants to merge 1 commit into
Conversation
- translate MediaWiki filetype-banned errors into a readable ValueError - name the offending extension and list the extensions the wiki accepts - re-raise every other APIError unchanged - closes #51
Contributor
Release previewMerging this PR would release v2.1.0 (current: Changelog preview (truncated)## v2.1.0 (2026-09-01)
### Features
- **file**: Report a rejected file extension clearly on upload
([`bb49392`](https://github.com/OpenSemanticLab/osw-python/commit/bb49392a4fc81801d3662613faae96944dd8ed91))
### Testing
- Rename oold.py to oold_test.py so its tests are collected
([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))
Preview via python-semantic-release and conventional commits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #51
Changes
WikiFileController.putcatchesmwclient.errors.APIErroraroundmw_site.uploadreraise_upload_error: on afiletype-*code it raises aValueErrornaming the file, the rejected extension and the host; every other API error is re-raised unchanged, with the original chained via__cause__get_allowed_file_extensions: best-effortsiteinfolookup that appends the accepted extensions to the message, and returnsNonerather than failing if that query does not worktests/test_wiki_file_upload_errors.pycovers the three MediaWiki codes, exception chaining, pass-through of unrelated errors, and the degraded message when siteinfo is unavailableRationale
An upload rejected for its extension surfaced only as a raw MediaWiki API code, which does not say what was wrong or which extensions the wiki accepts. MediaWiki uses
filetype-banned,filetype-banned-typeorfiletype-badtypedepending on version, so the check matches onfiletyperather than an exact code.The translation lives in a module-level function because exercising
putend to end needs a liveOSWinstance; this way the message logic is unit tested offline andputonly delegates.Known limitation, not addressed here
putcallsstore_entitybeforemw_site.upload, so a rejected upload still leaves an orphanWikiFilepage behind. That predates this change and needs its own decision about ordering or rollback.