Skip to content

Conversation

@pydanny
Copy link
Contributor

@pydanny pydanny commented Mar 13, 2025


name: Pull Request
about: Propose changes to the codebase
title: '[PR] Correct background tasks when used by FtResponse'
labels: 'bug'
assignees: ''


Related Issue

#336 - Background Tasks

Proposed Changes

This PR makes it possible for the FtResponse class to handle Background Tasks

Types of changes
What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist
Go over all the following points, and put an x in all the boxes that apply:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I am aware that this is an nbdev project, and I have edited, cleaned, and synced the source notebooks instead of editing .py or .md files directly.

Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.

@gitnotebooks
Copy link

gitnotebooks bot commented Mar 13, 2025

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/fasthtml/pull/674

@pydanny pydanny added the bug Something isn't working label Mar 13, 2025
fasthtml/core.py Outdated

def __response__(self, req):
cts,httphdrs,tasks = _xt_cts(req, self.content)
tasks = getattr(self, 'background', tasks)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think self.background will always be set, so I'm not sure this is doing anything? Also IIUC it's the wrong way around - we should use the manually added tasks in the response if there, and only then fall back to self.background, shouldn't we?

Either way, it's a good idea to have tests or examples that exercise your code so that you know for sure whether it's working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, we'll adjust the API accordingly and see about improving/adding to the tests and docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got the order of operations corrected, tasks now go for manual before self.background. Thanks @RensDimmendaal for the assist.

@pydanny pydanny force-pushed the background-tasks branch 4 times, most recently from ef2afce to 776ded9 Compare March 17, 2025 05:56
@jph00
Copy link
Contributor

jph00 commented Mar 17, 2025

Let me know when it's ready for review @pydanny (no hurry though)

@pydanny pydanny changed the title Correct background tasks when used by FtResponse Fix+docs for background tasks when used by FtResponse Mar 18, 2025
@pydanny pydanny force-pushed the background-tasks branch 8 times, most recently from 4396c41 to 065039d Compare March 19, 2025 22:55
@audreyfeldroy audreyfeldroy added the documentation Improvements or additions to documentation label Mar 20, 2025
@pydanny pydanny marked this pull request as ready for review March 21, 2025 22:49
@pydanny pydanny force-pushed the background-tasks branch 3 times, most recently from 9f5e24d to 017f54f Compare March 23, 2025 22:34
pydanny and others added 6 commits March 27, 2025 11:12
Co-Authored-By: Audrey M. Roy Greenfeld <audrey@feldroy.com>
Inspired by Starlette's tests for background tasks

Co-Authored-By: Audrey M. Roy Greenfeld <audrey@feldroy.com>
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
pydanny and others added 6 commits March 27, 2025 11:12
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
Co-authored-by: Daniel Roy Greenfeld <drg@answer.ai>
@pydanny
Copy link
Contributor Author

pydanny commented Mar 27, 2025

This is ready for review.

@hamelsmu
Copy link
Contributor

@pydanny This is a really well written tutorial. I love how you use code annotations for the docs with Quarto- extra love. Made it really easy to read and also learn about how it works.

@hamelsmu
Copy link
Contributor

hamelsmu commented Mar 28, 2025

@jph00 do you want to do a review or is this ok to merge? I find this feature to be very valuable in most things that I end up building.

@hamelsmu
Copy link
Contributor

Edit:

Q: Can we ship this now?
A: Yes.

Merging

@hamelsmu hamelsmu merged commit 32ca38c into main Mar 28, 2025
2 checks passed
@hamelsmu hamelsmu deleted the background-tasks branch March 28, 2025 00:15
@pydanny pydanny restored the background-tasks branch March 28, 2025 02:30
@pydanny pydanny mentioned this pull request Mar 28, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants