Skip to content

Fix multiple code quality and validation issues#159

Open
xenacode-art wants to merge 1 commit into
Wikimedia-Suomi:mainfrom
xenacode-art:fix/code-quality-improvements
Open

Fix multiple code quality and validation issues#159
xenacode-art wants to merge 1 commit into
Wikimedia-Suomi:mainfrom
xenacode-art:fix/code-quality-improvements

Conversation

@xenacode-art

Copy link
Copy Markdown
Contributor

Hi @zache-fi @ad-an-26 ,
This commit addresses several bugs and code quality issues found during code review:

  1. Add missing validator to superseded_similarity_threshold field

    • Field documentation stated 0.0-1.0 range but had no validator
    • Added MinValueValidator and MaxValueValidator for consistency
    • All other similar ORES threshold fields already had validators
  2. Fix inconsistent exception handling in is_living_person.py

    • Changed return value from True to False when birth date check fails
    • Added proper logging for debugging
    • Ensures consistent behavior with other exception handlers
  3. Add input validation to ISBN checker functions

    • Added None/empty string guards to prevent index out of bounds
    • Prevents potential crashes when invalid input is provided
    • Improves defensive programming practices
  4. Improve exception specificity in pending_revision.py

    • Split broad Exception catches into specific pywikibot exceptions
    • Now handles APIError, ServerError, and NoPageError separately
    • Better error logging for API vs unexpected errors
    • Enables more targeted error handling and monitoring
  5. Document and resolve wikitext TODO comment

    • Replaced TODO with clear explanation of str() conversion
    • Documents that MediaWiki API can return bytes or other types
    • Clarifies why explicit string conversion is necessary

All changes have been tested and pass existing test suite (70 tests).

This commit addresses several bugs and code quality issues found during
code review:

1. Add missing validator to superseded_similarity_threshold field
   - Field documentation stated 0.0-1.0 range but had no validator
   - Added MinValueValidator and MaxValueValidator for consistency
   - All other similar ORES threshold fields already had validators

2. Fix inconsistent exception handling in is_living_person.py
   - Changed return value from True to False when birth date check fails
   - Added proper logging for debugging
   - Ensures consistent behavior with other exception handlers

3. Add input validation to ISBN checker functions
   - Added None/empty string guards to prevent index out of bounds
   - Prevents potential crashes when invalid input is provided
   - Improves defensive programming practices

4. Improve exception specificity in pending_revision.py
   - Split broad Exception catches into specific pywikibot exceptions
   - Now handles APIError, ServerError, and NoPageError separately
   - Better error logging for API vs unexpected errors
   - Enables more targeted error handling and monitoring

5. Document and resolve wikitext TODO comment
   - Replaced TODO with clear explanation of str() conversion
   - Documents that MediaWiki API can return bytes or other types
   - Clarifies why explicit string conversion is necessary

All changes have been tested and pass existing test suite (70 tests).
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.

1 participant