Skip to content

Fix a silent upload error#1310

Closed
sztomi wants to merge 1 commit into
python-poetry:masterfrom
sztomi:fix_silent_upload_fail
Closed

Fix a silent upload error#1310
sztomi wants to merge 1 commit into
python-poetry:masterfrom
sztomi:fix_silent_upload_fail

Conversation

@sztomi
Copy link
Copy Markdown
Contributor

@sztomi sztomi commented Aug 20, 2019

Fixes #858 by first issuing a HEAD request and following a redirect.
This does not cover further redirects though, so it's possible to make this more robust. It does cover the most common use cases (PyPI and TestPyPI will work correctly)

See my comment for more details: #858 (comment)

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. (n/a: this is a bugfix)

Fixes python-poetry#858 by first issuing a HEAD request and following a redirect.
This does not cover further redirects though, so it's possible to make this
more robust. It does cover the most common use cases (PyPI and TestPyPI
will work correctly)
@sztomi sztomi force-pushed the fix_silent_upload_fail branch from 8c25b2e to 3d7ce0e Compare August 20, 2019 17:56
@sztomi
Copy link
Copy Markdown
Contributor Author

sztomi commented Aug 20, 2019

Unfortunately I do have a failing unit test and I don't know how to fix it.

This test fails:

    expected = """
Publishing simple-project (1.2.3) to PyPI
 - Uploading simple-project-1.2.3.tar.gz 0%
 - Uploading simple-project-1.2.3.tar.gz 100%
 - Uploading simple-project-1.2.3.tar.gz 100%

[UploadError]
HTTP Error 400: Bad Request

"""

    assert app_tester.get_display(True).startswith(expected)

The output gets unexpected whitespace, but I have no idea why. Any help is appreciated.

image

@brycedrennan brycedrennan added kind/bug Something isn't working as expected area/cli Related to the command line area/publishing Related to PyPI/PEP 503 publishing labels Aug 21, 2019
Copy link
Copy Markdown
Contributor

@brycedrennan brycedrennan left a comment

Choose a reason for hiding this comment

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

Thanks for contributing to poetry!

Do you think we could change it to manually follow redirects without needing to make two calls every time?

Alternatively, could we just output a meaningful error message and let the user fix the url?

- Uploading simple-project-1.2.3.tar.gz 0%
- Uploading simple-project-1.2.3.tar.gz 100%
- Uploading simple-project-1.2.3.tar.gz 100%
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.

Looks like you removed whitespace here - was that intentional? Might be related to the test failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, I totally did. Don't know why I didn't notice that. But it explains my test failure. I'll correct that.


# Check for a redirect first
resp = session.head(url)
if resp.status_code == status_codes.codes.moved:
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.

This approach means we'd have to make two requests every time, even when there is no redirect. Wouldn't we be able to just try the endpoint and then follow the redirect if necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's what I did originally, but that means POSTing the package data twice, so anyone who configured the wrong URL for their repo will have a big perf hit. On the other hand, a HEAD request is very cheap and isn't noticeable. Happy to do some benchmarks if you are not convinced.

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.

That's a good point that it would be expensive to POST twice.

@sztomi
Copy link
Copy Markdown
Contributor Author

sztomi commented Aug 30, 2019

Actually, I realized that 301 means permanently moved. So I'm going to open a different PR to follow the redirect at the time it is saved in the config.

@sztomi sztomi mentioned this pull request Aug 30, 2019
2 tasks
@sztomi
Copy link
Copy Markdown
Contributor Author

sztomi commented Aug 30, 2019

Superseded by the linked PR above ^

@sztomi sztomi closed this Aug 30, 2019
@sztomi sztomi deleted the fix_silent_upload_fail branch August 30, 2019 15:32
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 1, 2024

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 Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/cli Related to the command line area/publishing Related to PyPI/PEP 503 publishing kind/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload to PyPI silently fail

2 participants