Skip to content

add name option when wrapping async functions#12625

Merged
RayBB merged 1 commit into
masterfrom
fix/improve-wrapping-names
May 5, 2026
Merged

add name option when wrapping async functions#12625
RayBB merged 1 commit into
masterfrom
fix/improve-wrapping-names

Conversation

@RayBB

@RayBB RayBB commented May 5, 2026

Copy link
Copy Markdown
Collaborator

@lokesh pointed out that we weren't able to access wrapped functions properly in templates.

This is because the public function 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

@lokesh lokesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

tested locally. LGTM

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 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 name parameter to AsyncBridge.wrap() and copy wrapper metadata.
  • Apply explicit wrapper names for get_solr_works, gather_lazy_carousel_data, and add_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.

Comment thread openlibrary/plugins/worksearch/code.py
Comment thread openlibrary/plugins/openlibrary/partials.py
@RayBB

RayBB commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks! It's also up on testing and working well for the templates!

@RayBB RayBB merged commit 6ec4e0b into master May 5, 2026
11 checks passed
@RayBB RayBB deleted the fix/improve-wrapping-names branch May 5, 2026 18:34
shoaib-inamdar pushed a commit to shoaib-inamdar/openlibrary that referenced this pull request May 6, 2026
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.

3 participants