Skip to content

Refactor DB access, API naming, and enhance type safety - #270

Merged
MrIbrahem merged 4 commits into
mainfrom
update
Aug 24, 2026
Merged

MrIbrahem merged 4 commits into
mainfrom
update

Conversation

@MrIbrahem

@MrIbrahem MrIbrahem commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

Refactors database access, renames API entry points from PascalCase to snake_case, and adds type annotations across the codebase. The generic mdwiki_sql/toolforge_tools_sql_connect helpers are replaced by dedicated mdwiki_sql_update (writes) and mdwiki_sql_dict (reads) functions, and legacy select_md_sql is removed.

Changes

  • DB layer: split wiki_sql_connect/toolforge_tools_sql_connect into tf_sql_connect_update and tf_sql_connect_dict; replace mdwiki_sql(...)/select_md_sql(...) with mdwiki_sql_update(...)/mdwiki_sql_dict(...) in sql_for_mdwiki and all callers.
  • API renames (snake_case): Get_All_pagesget_all_pages, searchapi_search, Get_claimget_claim, Get_sitelinks_From_Qidget_sitelinks_from_qid, WD_Mergewd_merge, Get_Claims_APIget_claims_api, usercontribsuser_contribs, get_pageassessmentsget_page_assessments, isRedirectisredirect, Get_tagsget_tags, etc.
  • Type safety: add dict[str, Any] / list[...] annotations throughout src/db, src/newapi, src/md_core*, src/wprefs, and mark os.getenv(...) reads with or "" defaults.
  • super_page.MainPage: add is_bot_edit_invalid guard (blocks bot edits with empty summaries); minor reordering of helper methods.
  • bot_api: add get_page_info_from_wikipedia; defensive params.pop("apnamespace", None).

Testing

No tests included.

Split and modernize DB helpers: introduce tf_sql_connect_update / tf_sql_connect_dict and replace the old toolforge_tools_sql_connect; add mdwiki_sql_update and mdwiki_sql_dict and update callers across the codebase. Add TABLE_NAME constants and tighten typing for many functions. Refactor NewApi: rename/clarify methods (search->api_search, usercontribs->user_contribs), add type hints, improve params handling and add move implementation. Enhance page model (MainPage / pages dataclasses): stronger typing, revisions update via update_from_edit, bot edit validation, and many helper methods reorganized. Misc: package __init__ additions, small naming/formatting tweaks and pyright annotations.
Apply consistent snake_case naming, add type hints, and strengthen defaults across the codebase. Environment variables now fallback to empty strings to avoid None issues. Rename several WD API helpers (Get_sitelinks_From_Qid/Get_Claims_API/Get_claim/WD_Merge -> get_sitelinks_from_qid/get_claims_api/get_claim/wd_merge) and unify request signatures with typed params. Enhance NewApi: search returns list[dict], upload returns a success dict and a new get_page_info_from_wikipedia helper. Increase load_main_api cache size and tighten exception chaining in replaceExcept. Miscellaneous logging/typing fixes for clarity and safety.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 74997e3b-3059-4472-b69e-19b2b56b6cc1


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MrIbrahem MrIbrahem left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review summary

Large mechanical refactor (split DB helpers + snake_case renames + type annotations). Intent is good and most edits are consistent, but the core DB helper is broken and several renamed callers were left dangling.

Verdict: Comment 💬 (forced — you're the PR author; underlying assessment is 🔴 blocking issues found)

Title

Current: Refactor DB access, API naming, and enhance type safety

  • The title is accurate. Optional: prefix with refactor: to match the recent conventional-commit style seen in merged PRs (e.g. refactor: split DB helpers and rename API methods to snake_case). Not required.

Highlights

  • Consistent snake_case rename across the API surface (Get_All_pagesget_all_pages, searchapi_search, Get_claimget_claim, etc.).
  • Good defensive fix: params.pop("apnamespace", None) instead of del (avoids KeyError).
  • New is_bot_edit_invalid guard blocks bot edits with empty summaries — sensible safety check.
  • Type annotations added broadly without restructuring logic.

Issues found

  • 🔴 Blocking: 4 (see inline comments + the items below that fall outside the diff hunks).
  • 🟡 Suggestions: 3

Blocking (details)

  1. src/db/mdapi_sql/sql_td_bot.pyDbConfig.to_dict() raises KeyError: 'conv' on every call. The conv key was removed from the dict literal but is still accessed on the line before it's created. Every DB query in this PR goes through _load_db_config().to_dict(), so all DB access crashes. Even after fixing the crash, the DATE→str converter is lost because data["conv"] is overwritten on the next line after the override is applied.
  2. tf_sql_connect_update returns False on the success path (the only return statements are return False), so every INSERT/UPDATE/DELETE reports failure regardless of outcome.
  3. Renamed/removed methods still referenced in this PR's own touched files (not inline-commentable because they sit outside the diff hunks — please fix):
    • src1/md_core/mdpy/red.py:210,243,245api_new.Search, api_new.Get_Newpages, mdwiki_api_call.Get_UserContribs
    • src1/md_core/mdpy/imp.py:163,196api_new.Search, api_new.Get_Newpages
    • src1/newupdater/medask.py:131,149,151api_new.Search, api_new.Get_Newpages, mdwiki_api_call.Get_UserContribs
    • api_search also dropped the return_dict parameter — replace1.py:127 / one_job.py:168 still pass return_dict=False, which is now an invalid kwarg (TypeError). And api_search now always returns dicts (full search hits), not title strings, so any downstream code expecting strings must be updated.
  4. sql_for_mdwiki.select_md_sql was deleted but is still used in untouched files: src1/md_core/mdpy/orred.py:55 and src1/copy_text/text_bot.py:21AttributeError.

Suggestions

  • 🟡 Add a smoke test that imports sql_td_bot and calls to_dict() (and ideally opens a connection) — the KeyError would have been caught immediately.
  • 🟡 After a repo-wide rename, grep for the old names to catch dangling callers (the src1/ breakage above).
  • 🟡 The repeated params: dict[str, Any] = {...} local-variable annotations are valid but noisy; reverting to plain params = {...} is optional.

Comment thread src/db/mdapi_sql/sql_td_bot.py
Comment thread src/db/mdapi_sql/sql_td_bot.py
Comment thread src1/md_core/mdpy/replace1.py
Comment thread src1/find_replace_bot/one_job.py
@MrIbrahem
MrIbrahem merged commit 1161f6c into main Aug 24, 2026
2 checks passed
@MrIbrahem
MrIbrahem deleted the update branch August 24, 2026 01:10
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