Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Block.aload method and remove @sync_compatible from Block.load #16341

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

desertaxle
Copy link
Member

@desertaxle desertaxle commented Dec 11, 2024

This PR improves type hinting on Block.load by removing the @sync_compatible decorator and using @async_dispatch instead.

I had to update @async_dispatch to handle class methods and update the dispatch behavior in tasks and flows to match the behavior provided by @sync_compatible.

Also, @inject_client might be a thorn in our side because it makes wrapped functions async. To handle that in this PR, I removed @inject_client from Block.load and moved the client retrieval inside the method. There's a weird split where sometimes we can use the sync client, and other times we have to use the async client, but we can clean that up once we remove @async_dispatch.

Related to #16292

Copy link

codspeed-hq bot commented Dec 11, 2024

CodSpeed Performance Report

Merging #16341 will not alter performance

Comparing block_aload (972c8bc) with main (6bfce9e)

Summary

✅ 3 untouched benchmarks

@desertaxle desertaxle marked this pull request as ready for review December 11, 2024 17:55
Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

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

lgtm!

@desertaxle desertaxle merged commit 3ea3428 into main Dec 11, 2024
40 checks passed
@desertaxle desertaxle deleted the block_aload branch December 11, 2024 18:22
Comment on lines +78 to +90
...


@overload
def inject_client(
fn: Callable[P, R],
) -> Callable[P, R]:
...


def inject_client(
fn: Callable[P, Union[Coroutine[Any, Any, R], R]],
) -> Callable[P, Union[Coroutine[Any, Any, R], R]]:
Copy link
Contributor

@mjpieters mjpieters Dec 19, 2024

Choose a reason for hiding this comment

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

@desertaxle Why did you add this overload?

The implementation uses await on the callable argument (fn) so it must produce an awaitable, and nowhere in the prefect codebase is @inject_client used on a regular function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, you're absolutely right. I was working with @inject_client while I was making Block.load sync. This was from something that ultimately didn't work, and I forgot to remove it. I'll make a note to remove this, but feel free to remove it if you're in the neighborhood.

Copy link
Contributor

Choose a reason for hiding this comment

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

@desertaxle already on it 😁 See #16463.

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.

3 participants