Skip to content

[3.13] gh-133745: Fix asyncio task factory name/context kwarg breaks #133948

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

Open
wants to merge 9 commits into
base: 3.13
Choose a base branch
from

Conversation

graingert
Copy link
Contributor

@graingert graingert commented May 12, 2025

@graingert graingert changed the title gh-128308: Fix asyncio task factory name/context kwarg breaks gh-133745: Fix asyncio task factory name/context kwarg breaks May 12, 2025
@graingert graingert force-pushed the fix-name-passed-to-task-factory branch from f298146 to 5c3c953 Compare May 12, 2025 19:13
@graingert graingert changed the title gh-133745: Fix asyncio task factory name/context kwarg breaks [3.13] gh-133745: Fix asyncio task factory name/context kwarg breaks May 12, 2025
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I think this is the right thing, just one refactoring suggestion.

We should ask Alice to try this (maybe after it's in the nightly builds).

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

To be clear, this is supposed to happen instead of the rollback, right?

@graingert
Copy link
Contributor Author

To be clear, this is supposed to happen instead of the rollback, right?

that's my understanding, yet

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Despite what the comment says, you're just removing the try/except here. Was that intentional?

@graingert
Copy link
Contributor Author

Despite what the comment says, you're just removing the try/except here. Was that intentional?

Ah it looks like that in the diff, but I also added an else and removed the early return. Execution follows after the if/else and returns the task deleting it 'after' the return

@gvanrossum
Copy link
Member

Got it. What's difficult or controversial about the news fragment? Just that we're waffling about the feature? I think it's reasonable to say something like this:

In 3.13.3 we accidentally changed the signature of create_task() and how it calls a custom task factory in a backwards incompatible way. Since some 3rd party libraries have already made changes to work around the issue that might break if we simply reverted the changes, we're instead changing things to be backwards compatible with 3.13.2 while still supporting those workarounds. In particular, the special-casing of name and context is back (until 3.14) and consequently eager tasks may still find that their name hasn't been set before they execute their first line of code.

WDYT? If you agree, let's merge this.

@@ -0,0 +1 @@
In 3.13.3 we accidentally changed the signature of the asyncio ``create_task()`` family of methods and how it calls a custom task factory in a backwards incompatible way. Since some 3rd party libraries have already made changes to work around the issue that might break if we simply reverted the changes, we're instead changing things to be backwards compatible with 3.13.2 while still supporting those workarounds for 3.13.3. In particular, the special-casing of ``name`` and ``context`` is back (until 3.14) and consequently eager tasks may still find that their name hasn't been set before they execute their first yielding await.
Copy link
Contributor Author

@graingert graingert May 14, 2025

Choose a reason for hiding this comment

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

do we want to say create_task() family of methods or just list out them all: loop.create_task, TaskGroup.create_task and asyncio.create_task

Copy link
Member

Choose a reason for hiding this comment

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

I see no strong reason to spell them all out -- the 3.13.3 changes affect all methods named create_task and only those.

@graingert graingert marked this pull request as ready for review May 14, 2025 08:16
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I am happy with the code and the news blurb.

I'd like @kumaraditya303 to review this too, to be extra sure that we don't have to backtrack more in 3.13.5.

And don't we need something in the docs about this change? I just noticed that it looks like the previous change didn't even have a versionchanged (3.13.3) directive. We should add that retroactively, and another versionchanged (3.13.4) mentioning what we changed there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants