Skip to content

fix: make extra_name of try_import optional and the install hint reusable - #2247

Merged
Pijukatel merged 1 commit into
masterfrom
claude/gallant-tesla-cuzxju
Sep 22, 2026
Merged

Pijukatel merged 1 commit into
masterfrom
claude/gallant-tesla-cuzxju

Conversation

@Pijukatel

@Pijukatel Pijukatel commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

extra_name landed in #2208 as a required keyword-only argument in a patch release, breaking every external caller:
import apify.scrapy fails with

TypeError: try_import() missing 1 required keyword-only argument: 'extra_name'

This gives it a default — every call site here passes it explicitly, so user-facing messages are unchanged — and adds package_name, since the hint hardcoded crawlee[<extra>] and pointed SDK users at an extra that does not exist here.

Also fixes two IndexError already in the helper: e.args[0] on an argless ImportError (the nested-guard case the docstring anticipates), and extra_name[0] on an empty list.

…reusable

`extra_name` was introduced in #2208 as a required keyword-only argument. All call
sites inside this package were updated in the same PR, so requiring it gained nothing
internally, but it silently broke every external caller of the helper in what shipped
as a patch release (1.10.1).

The Apify SDK guards its Scrapy integration with this helper, so `import apify.scrapy`
now fails on any fresh install:

    TypeError: try_import() missing 1 required keyword-only argument: 'extra_name'

Giving `extra_name` a default restores that compatibility; every call site in this
package passes it explicitly, so the messages users see are unchanged.

While here:

- Add a `package_name` argument, defaulting to this package. The install hint had the
  distribution name hardcoded, so a downstream package reusing the helper would point
  its users at `crawlee[<extra>]` for an extra that only exists in their own
  distribution.
- Read the original message with `str(e)` instead of `e.args[0]`, which raised
  `IndexError` on an `ImportError` carrying no arguments — a case the docstring
  explicitly anticipates for nested guards.
- Normalize `extra_name` to a list in `_get_install_hint` so an empty collection
  cannot raise `IndexError` either.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014KjVQGrzsBfgKerTpaVf3o
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Sep 22, 2026
@apify-service-account apify-service-account added the t-tooling Issues with this label are in the ownership of the tooling team. label Sep 22, 2026
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.72%. Comparing base (3a35606) to head (1c681a8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2247      +/-   ##
==========================================
- Coverage   93.73%   93.72%   -0.01%     
==========================================
  Files         181      181              
  Lines       12877    12878       +1     
==========================================
  Hits        12070    12070              
- Misses        807      808       +1     
Flag Coverage Δ
unit 93.72% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pijukatel Pijukatel added the adhoc Ad-hoc unplanned task added during the sprint. label Sep 22, 2026

@janbuchar janbuchar 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.

LGTM

@Pijukatel
Pijukatel merged commit 626f334 into master Sep 22, 2026
36 of 43 checks passed
@Pijukatel
Pijukatel deleted the claude/gallant-tesla-cuzxju branch September 22, 2026 08:06
Pijukatel added a commit to apify/apify-sdk-python that referenced this pull request Sep 22, 2026
It made backwards-incompatible changes to `crawlee._utils.try_import`

Unreleased version of Crawlee 1.10.2 should include backwards compatible
fix apify/crawlee-python#2247
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants