Skip to content

SEP-1450: Extract reraise_upstream_tasks_errors context manager for gateway proxy - #1119

Merged
yyyyyyyan merged 6 commits into
mainfrom
SEP-1450
Jul 15, 2026
Merged

SEP-1450: Extract reraise_upstream_tasks_errors context manager for gateway proxy#1119
yyyyyyyan merged 6 commits into
mainfrom
SEP-1450

Conversation

@marcuscruz-percona

Copy link
Copy Markdown
Contributor

Summary

  • Replace the repeated try/except (HTTPException, OSError) blocks across the periodic-tasks and task-history proxy routes with a single reraise_upstream_tasks_errors() context manager, keeping the SEP→Tasks gateway error contract in one place.
  • Behaviour is unchanged: upstream client errors (<500) re-raise intact, server errors (>=500) and connection-level OSErrors map to 502.

Tested

  • pytest tests/app/sep/api/test_proxy.py -v — new unit tests green
  • Existing periodic-tasks / task-history route tests still pass

Checklist

  • New/modified functions have type hints and rST docstrings
  • New tests added for new features or bug fixes
  • All tests pass locally (make test)
  • Pre-commit hooks pass (make run-pre-commit)
  • Database migrations generated if models changed (make makemigrations)
  • User-facing changes documented (README, inline help, UI text)
  • Configuration changes documented with examples
  • Changelog fragment added under changelog.d/ if the change is user-facing (make changelog-add), or confirmed N/A (internal-only change, or a same-release-cycle fix for an unreleased sibling ticket)

…ateway proxy

Replace the repeated try/except (HTTPException, OSError) blocks in the
periodic-tasks and task-history proxy routes with a single
reraise_upstream_tasks_errors() context manager, keeping the SEP gateway
error contract in one place. Add unit tests covering clean blocks,
client-error passthrough, server-error/OSError -> 502 mapping, and
unrelated-exception propagation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 centralizes SEP→Tasks gateway error handling by introducing a shared reraise_upstream_tasks_errors() context manager and updating the periodic-tasks and task-history proxy routes to use it, keeping the proxy error contract consistent across endpoints.

Changes:

  • Add reraise_upstream_tasks_errors() context manager in app/sep/api/proxy.py to wrap upstream Tasks API calls and apply the existing mapping rules.
  • Replace repeated try/except (HTTPException, OSError) blocks in periodic-tasks and task-history routes with the new context manager.
  • Add unit tests covering the context manager’s behavior for clean blocks, upstream client/server errors, OSError, and unrelated exceptions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
app/sep/api/proxy.py Adds a context manager wrapper for the existing upstream error-mapping helper.
app/sep/api/routes/task_history.py Switches proxy calls to use the shared context manager instead of inline try/except blocks.
app/sep/api/routes/periodic_tasks.py Switches proxy calls to use the shared context manager instead of inline try/except blocks.
tests/app/sep/api/test_proxy.py Adds focused unit tests for the new context manager behavior.

Comment thread app/sep/api/proxy.py Outdated
@marcuscruz-percona marcuscruz-percona added the qa passed Tests for this PR are completed and successful. label Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  app/sep/api
  proxy.py
  app/sep/api/routes
  periodic_tasks.py
  task_history.py
  app/sep/apps/mysql_backups/restore
  deps.py
  app/sep/sync/syncers/mysql
  syncer.py
Project Total  

This report was generated by python-coverage-comment-action

@yyyyyyyan
yyyyyyyan merged commit 80353e5 into main Jul 15, 2026
17 checks passed
@yyyyyyyan
yyyyyyyan deleted the SEP-1450 branch July 15, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python qa passed Tests for this PR are completed and successful.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants