Skip to content

Comments

executor: propagate original error even if pkg.to_dependency() fails#10340

Closed
lotheac wants to merge 1 commit intopython-poetry:mainfrom
lotheac:push-mmvstsnzlvmq
Closed

executor: propagate original error even if pkg.to_dependency() fails#10340
lotheac wants to merge 1 commit intopython-poetry:mainfrom
lotheac:push-mmvstsnzlvmq

Conversation

@lotheac
Copy link

@lotheac lotheac commented Apr 16, 2025

this fixes the following regression, introduced somewhere between 1.8.4 and 2.0.1:

a git dependency which fails wheel build does not output the underlying error that caused the wheel build failure. eg.

podman run -ti -w /tmp --entrypoint /bin/sh --rm python:3.13.3-alpine3.21 -c "pip install poetry && poetry new . && poetry add 'python-kadmin @ git+https://github.com/authentik-community/[email protected]'"

the root cause is that the exception handling in _execute_operation() calls pkg.to_dependency(), which fails like:

ValueError: Invalid git url "/root/.cache/pypoetry/virtualenvs/tmp-6WcazSRI-py3.13/src/python-kadmin"

and the underlying build error is therefore never output.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Bug Fixes:

  • Ensure that the underlying build error is output even if pkg.to_dependency() fails during package wheel build

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 16, 2025

Reviewer's Guide by Sourcery

This pull request fixes a regression where the underlying build error of a git dependency was not outputted when the wheel build failed. The issue was caused by exception handling in _execute_operation() which called pkg.to_dependency(), and a failure in this call would mask the original build error. The fix involves adding a try-except block to catch the ValueError that occurs when pkg.to_dependency() fails, ensuring that the original error is propagated.

Sequence diagram for error handling in _execute_operation

sequenceDiagram
  participant Executor
  participant Package
  participant Pip

  Executor->>Package: pkg.to_dependency()
  alt ValueError
    Package-->>Executor: Raises ValueError
    Executor->>Executor: Catch ValueError
    Executor-->>Executor: Propagate original error
  else No ValueError
    Package-->>Executor: Returns Dependency
    Executor->>Pip: pip wheel --no-cache-dir --use-pep517 <requirement>
    alt Pip wheel fails
      Pip-->>Executor: Raises BuildError
      Executor-->>Executor: Propagate BuildError
    else Pip wheel succeeds
      Pip-->>Executor: Returns Wheel
    end
  end
Loading

File-Level Changes

Change Details Files
Propagate the original error even if pkg.to_dependency() fails.
  • Added a try-except block to catch ValueError when calling pkg.to_dependency().
  • The original error is now propagated, preventing the underlying build error from being masked.
src/poetry/installation/executor.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @lotheac - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why the ValueError might occur and why it's safe to ignore in this context.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lotheac lotheac force-pushed the push-mmvstsnzlvmq branch 2 times, most recently from 7c9271e to 5a8d695 Compare April 20, 2025 07:54
this fixes the following regression, introduced somewhere between 1.8.4
and 2.0.1:

a git dependency which fails wheel build does not output the underlying
error that caused the wheel build failure. eg.

	podman run -ti -w /tmp --entrypoint /bin/sh --rm python:3.13.3-alpine3.21 -c "pip install poetry && poetry new . && poetry add 'python-kadmin @ git+https://github.com/authentik-community/[email protected]'"

the root cause is that the exception handling in _execute_operation()
calls pkg.to_dependency(), which fails like:

	ValueError: Invalid git url "/root/.cache/pypoetry/virtualenvs/tmp-6WcazSRI-py3.13/src/python-kadmin"

and the underlying build error is therefore never output.
@lotheac lotheac force-pushed the push-mmvstsnzlvmq branch from 5a8d695 to 6ec31e2 Compare April 23, 2025 05:55
Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

At first, thanks for providing an exact repro of the issue. 👍

Although the change clearly improves the behavior, I think it is more a workaround than a valid fix. The suppressed exception is the real bug. When testing the repro with the change, you can see the following line at the end of the output:

You can verify this by running pip wheel --no-cache-dir --use-pep517 "/root/.cache/pypoetry/virtualenvs/tmp-6WcazSRI-py3.13/src/python-kadmin".

which is wrong because it references the cache directory instead of the git URL.

The reason is probably the following hack:

package._source_url = str(source.path)

We overwrite the source URL and reset it later:

if not package.develop:
package._source_url = original_url

Maybe, it is enough if we put some lines in a try-except and always reset the source URL in case of an exception.

Further, we should probably add a test. Maybe, the following test can be extended (or at least used as a starting point):

def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(

The test will probably be more complicated than the fix. I may take a look for myself later.

@lotheac
Copy link
Author

lotheac commented Apr 28, 2025

@radoering thank you for your review.

I'm not super familiar with the poetry code, so I would appreciate it if you could take a look at a better fix. If that's ok with you, I think we can close this PR.

@github-actions
Copy link

github-actions bot commented Jun 2, 2025

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants