Skip to content

Return task when creating a task#3114

Merged
ahopkins merged 2 commits into
mainfrom
issue3090
Dec 31, 2025
Merged

Return task when creating a task#3114
ahopkins merged 2 commits into
mainfrom
issue3090

Conversation

@ahopkins

Copy link
Copy Markdown
Member

Closes #3090

When creating a task from the Sanic app, we return the Asyncio task so that we can call the result later.

Copilot AI review requested due to automatic review settings December 31, 2025 08:02
@ahopkins ahopkins requested a review from a team as a code owner December 31, 2025 08:02

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 enables users to retrieve the result of tasks created via app.add_task() by adding a return statement to the internal task wrapper. Previously, task results were discarded even though the Task object itself was returned.

Key changes:

  • Modified _prep_task() internal wrapper to return the awaited task result
  • Added comprehensive tests for both direct coroutine and callable task patterns

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sanic/app.py Added return statement in the _prep_task method's internal do() coroutine to preserve and propagate task results
tests/test_tasks.py Added two new test cases verifying that task results can be retrieved via both await task and task.result() for coroutines and callables

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

@ahopkins ahopkins merged commit 82d8cc4 into main Dec 31, 2025
26 checks passed
@ahopkins ahopkins deleted the issue3090 branch December 31, 2025 11:25
@codecov

codecov Bot commented Dec 31, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.893%. Comparing base (002c8c2) to head (3e4f05d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3114   +/-   ##
=========================================
  Coverage   87.893%   87.893%           
=========================================
  Files          105       105           
  Lines         8078      8078           
  Branches      1281      1281           
=========================================
  Hits          7100      7100           
  Misses         671       671           
  Partials       307       307           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Background task results are lost

2 participants