add name option when wrapping async functions#12625
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes template access to sync wrappers around async helpers by letting AsyncBridge.wrap() override the wrapper name that public() exposes to Templetor. In the Open Library codebase, this affects async-backed helpers that are called from templates but are implemented as sync shims for backward compatibility.
Changes:
- Add an optional
nameparameter toAsyncBridge.wrap()and copy wrapper metadata. - Apply explicit wrapper names for
get_solr_works,gather_lazy_carousel_data, andadd_availability. - Keep existing async implementations unchanged while fixing the template-visible sync names.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
openlibrary/utils/async_utils.py |
Extends the async-to-sync wrapper helper with an optional explicit wrapper name. |
openlibrary/plugins/worksearch/code.py |
Registers the sync worksearch wrapper under get_solr_works for template use. |
openlibrary/plugins/openlibrary/partials.py |
Registers the carousel data wrapper under gather_lazy_carousel_data for template access. |
openlibrary/core/lending.py |
Registers the availability wrapper under add_availability for template/global access. |
Collaborator
Author
|
Thanks! It's also up on testing and working well for the templates! |
shoaib-inamdar
pushed a commit
to shoaib-inamdar/openlibrary
that referenced
this pull request
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@lokesh pointed out that we weren't able to access wrapped functions properly in templates.
This is because the
publicfunction uses__name__for the key in the templates and we weren't setting that correctly. I think this wasn't noticed until now because most of the wrapped functions are only used from python.This lets us set an explicit name to be used.
Technical
Testing
Screenshot
Stakeholders