Fix critical bugs in app_urls #1

Open
matitos wants to merge 5 commits from fix-critical-bugs into main
pull from: fix-critical-bugs
Owner

Summary

Fixes six critical bugs found during a code review of the app_urls service.

SQL injection (init_db.py)

Replaced string-formatted SQL INSERT statements with parameterized queries in insert_status_pattern_matching and search insertion, preventing SQL injection from arbitrary values in init_data.json.

Duplicate periodic task primary key (scheduled_tasks.json)

"Notify status" and "Process MissingKids URLs - batch=50" both declared pk: 4. Reassigned "Notify status" to a unique pk: 15 so loaddata no longer overwrites/collides on load.

Undefined variable in closure (db_utils.py)

_get_status_pattern_matching accepted a url parameter but used obj_url.url captured from the enclosing scope. Now uses its own parameter, making the function self-contained and correct regardless of the caller scope.

Wrong model field in template (url_detail.html)

Replaced url_content.image_urls with the actual field name url_content.images_url so image URLs render correctly.

Celery queue mismatch (settings.py)

CELERY_TASK_QUEUES declared queues (default, low) but tasks route to light/heavy and supervisord runs workers on default/light/heavy. Updated settings to (default, light, heavy) so tasks are delivered to the running consumers.

Broken publish route

Templates link to /task/publish_<id> but no such route existed, returning 404. Added a publish view and URL route that invokes Publisher().publish(id).

Verification

  • python -m py_compile passes for all modified Python files
  • scheduled_tasks.json validates as JSON with no duplicate periodic-task primary keys
## Summary Fixes six critical bugs found during a code review of the `app_urls` service. ### SQL injection (init_db.py) Replaced string-formatted SQL INSERT statements with parameterized queries in `insert_status_pattern_matching` and search insertion, preventing SQL injection from arbitrary values in `init_data.json`. ### Duplicate periodic task primary key (scheduled_tasks.json) "Notify status" and "Process MissingKids URLs - batch=50" both declared `pk: 4`. Reassigned "Notify status" to a unique `pk: 15` so `loaddata` no longer overwrites/collides on load. ### Undefined variable in closure (db_utils.py) `_get_status_pattern_matching` accepted a `url` parameter but used `obj_url.url` captured from the enclosing scope. Now uses its own parameter, making the function self-contained and correct regardless of the caller scope. ### Wrong model field in template (url_detail.html) Replaced `url_content.image_urls` with the actual field name `url_content.images_url` so image URLs render correctly. ### Celery queue mismatch (settings.py) `CELERY_TASK_QUEUES` declared queues `(default, low)` but tasks route to `light`/`heavy` and supervisord runs workers on `default`/`light`/`heavy`. Updated settings to `(default, light, heavy)` so tasks are delivered to the running consumers. ### Broken publish route Templates link to `/task/publish_<id>` but no such route existed, returning 404. Added a `publish` view and URL route that invokes `Publisher().publish(id)`. ## Verification - `python -m py_compile` passes for all modified Python files - `scheduled_tasks.json` validates as JSON with no duplicate periodic-task primary keys
matitos added 1 commit 2026-09-02 13:13:57 +02:00
- init_db.py: parameterize SQL queries to prevent SQL injection
- scheduled_tasks.json: resolve duplicate periodic task pk (4 -> 15)
- db_utils.py: use function parameter in _get_status_pattern_matching
  instead of capturing the enclosing scope variable
- url_detail.html: fix wrong field name image_urls -> images_url
- settings.py: align Celery queues (default/light/heavy) with the task
  queues and supervisord workers
- Add /task/publish_<id>/ route to fix broken publish links in templates
matitos added 1 commit 2026-09-02 14:42:15 +02:00
Add unit tests and Gitea CI workflow for bug fixes
Tests / test (pull_request) Failing after 3m11s
d18eda2fc4
- Add fetcher/tests/ with 21 tests covering all bug fixes:
  - test_utils: get_with_protocol URL normalization (5 tests)
  - test_config: scheduled_tasks.json PK uniqueness, Celery queue
    settings (7 tests)
  - test_publish: URL routing and view for /task/publish_<id>/ (4 tests)
  - test_template_field: url_detail.html renders images_url field (2 tests)
  - test_search_postprocess: URL host filtering and param stripping (3 tests)
- Replace empty fetcher/tests.py with tests/ package
- Add .gitea/workflows/test.yml: runs on PRs and pushes to main,
  installs dependencies and runs `manage.py test fetcher.tests`
matitos added 1 commit 2026-09-02 16:39:37 +02:00
Point Search-Engines-Scraper dependency to Gitea mirror
Tests / test (pull_request) Successful in 7m9s
fa9d552873
The Gitea CI runner has no outbound access to github.com.
Mirror the repository on the local Gitea instance so pip install
succeeds in CI.

Co-Authored-By: opencode <noreply@opencode.ai>
matitos added 1 commit 2026-09-02 17:00:21 +02:00
Wrap gnews, GoogleNews, and search_engines imports in try/except
so the module loads without those packages installed. This allows
the test suite to run on the Gitea runner without outbound GitHub
access.

Also revert requirements.txt back to the GitHub URL for the
Search-Engines-Scraper dependency.

Co-Authored-By: opencode <noreply@opencode.ai>
matitos added 1 commit 2026-09-02 17:06:45 +02:00
Filter out git+https dependencies in CI
Tests / test (pull_request) Successful in 7m2s
c7104ad8f0
The Gitea runner can't clone github.com repos via pip.
Since the tests don't need Search-Engines-Scraper, exclude
git+ lines from requirements during CI install.

Co-Authored-By: opencode <noreply@opencode.ai>
All checks were successful
Tests / test (pull_request) Successful in 7m2s
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix-critical-bugs:fix-critical-bugs
git checkout fix-critical-bugs
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: matitos/matitos_news#1