Skip to content

Fix Migration Conflicts and Re-implement Test Mode - #137

Open
sergyDwhiz wants to merge 9 commits into
Wikimedia-Suomi:mainfrom
sergyDwhiz:feature/2-fixed
Open

Fix Migration Conflicts and Re-implement Test Mode#137
sergyDwhiz wants to merge 9 commits into
Wikimedia-Suomi:mainfrom
sergyDwhiz:feature/2-fixed

Conversation

@sergyDwhiz

Copy link
Copy Markdown
Contributor

This Patch brings back the test mode feature from #21, this time with properly ordered database migrations that aligns with the latest upstream changes. The earlier version had to be reverted because of migration file numbering conflicts, so this PR focuses on rebuilding the feature cleanly and conflict-free.

  • I added a new Boolean field test_mode to the WikiConfiguration model allowing the system to toggle between live data and test data.
  • Added a JSON array field test_revision_ids to store specific revision IDs for controlled testing scenarios.
  • When test mode is active, the query switches from the flaggedpages table to the revision table and filters results using the configured test revision IDs.
  • Updated configuration endpoints to handle test mode settings, including input validation (integer-only IDs) and proper saving to the database.
  • All relevant API responses now include both the test mode status and the configured revision IDs.

Related to #21

- Add test_mode (Boolean) and test_revision_ids (JSON) fields to WikiConfiguration model
- Update wiki_client.py to use test revision IDs when test mode is enabled
- Add API endpoints to save and retrieve test mode configuration
- Generate new migration
@ademolaomosanya ademolaomosanya added enhancement New feature or request ready for review Indicates the PR is complete and ready for maintainer review. and removed enhancement New feature or request labels Oct 29, 2025
@sergyDwhiz

Copy link
Copy Markdown
Contributor Author

Hi @zache-fi, please any thoughts on this so far?

Copilot AI review requested due to automatic review settings November 1, 2025 10:30
@sergyDwhiz

Copy link
Copy Markdown
Contributor Author

Branch is updated to "main"

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a test mode feature to the wiki reviews system, allowing users to specify specific revision IDs for testing instead of using live flaggedpages data. The feature is controlled through the WikiConfiguration model and affects how pending pages are fetched.

Key changes:

  • Added test_mode (boolean) and test_revision_ids (list) fields to the WikiConfiguration model
  • Modified fetch_pending_pages in WikiClient to use test revision IDs when test mode is enabled
  • Updated API views to expose and accept the new configuration fields

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
app/reviews/models/wiki_configuration.py Added test_mode and test_revision_ids fields to WikiConfiguration model
app/reviews/migrations/0018_add_test_mode_fields.py Database migration to add the new test mode fields
app/reviews/views.py Updated views to expose and handle test mode configuration in API responses and updates
app/reviews/services/wiki_client.py Modified fetch_pending_pages to use test revision IDs instead of flaggedpages when test mode is enabled

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +157 to +158
# Build CSV string for SQL IN clause
ids_csv = ",".join(valid_ids)

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The ids_csv variable is directly interpolated into a SQL query at line 190 without parameterization. While the IDs are validated as integers, this pattern is vulnerable to SQL injection if the validation logic changes. Use parameterized queries or ensure this construction is well-documented as requiring validated integer strings only.

Suggested change
# Build CSV string for SQL IN clause
ids_csv = ",".join(valid_ids)
# Prepare parameterized IN clause for revision IDs
placeholders = ",".join(["%s"] * len(valid_ids))

Copilot uses AI. Check for mistakes.
FROM
(SELECT rev_page AS fp_page_id,
rev_id AS fp_stable,
BINARY('20250901000000') AS fp_pending_since

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded timestamp '20250901000000' (September 1, 2025) is a magic value without explanation. This should either be documented with a comment explaining why this specific date is used for test mode, or extracted as a named constant.

Copilot uses AI. Check for mistakes.
Comment thread app/reviews/views.py
Comment on lines +592 to +593
if cleaned.isdigit():
validated_ids.append(cleaned)

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The validation logic only accepts positive integers using isdigit(), which will reject valid revision IDs if they arrive as actual integers or fail to detect negative numbers passed as strings with a minus sign. Additionally, storing IDs as strings in a JSONField intended for integers is inconsistent. Convert to integers: replace line 593 with validated_ids.append(int(cleaned)) after using cleaned.lstrip('-').isdigit() or try/except int() conversion.

Suggested change
if cleaned.isdigit():
validated_ids.append(cleaned)
try:
validated_ids.append(int(cleaned))
except ValueError:
continue

Copilot uses AI. Check for mistakes.
Comment on lines +146 to +150
for item in test_ids:
try:
val = int(str(item).strip())
valid_ids.append(str(val))
except (ValueError, TypeError):

Copilot AI Nov 1, 2025

Copy link

Choose a reason for hiding this comment

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

The validation logic converts integers to strings for SQL interpolation but stores them as strings. This is inconsistent with lines 589-593 in views.py which also stores IDs as strings. Since revision IDs are integers, they should be stored as integers in the JSONField and only converted to strings when building the SQL query. This reduces confusion and ensures type consistency.

Copilot uses AI. Check for mistakes.
Comment thread app/reviews/views.py Outdated
sergyDwhiz and others added 3 commits November 1, 2025 11:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Create merge migration 0019 to handle conflicting 0018 migrations
- Resolve conflict between test mode fields and statistics refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Indicates the PR is complete and ready for maintainer review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants