| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Reviewer's GuideAdds a guarded retry of file upload after successful package registration when encountering specific 400 responses, and introduces a test to verify the upload-register-upload flow. Sequence diagram for guarded retry upload after package registrationsequenceDiagram
actor User
participant Uploader
participant Server
User->>Uploader: publish_package(file)
Uploader->>Server: POST upload_file(file, registered=false)
Server-->>Uploader: 400 Bad Request
alt status 400 and contains was ever registered and registered is false
Uploader->>Server: POST register_package()
Server-->>Uploader: 200 OK
Uploader->>Server: POST upload_file(file, registered=true)
alt second upload succeeds
Server-->>Uploader: 200 OK
Uploader-->>User: publish succeeded
else second upload still 400
Server-->>Uploader: 400 Bad Request
Uploader->>Uploader: resp.raise_for_status()
Uploader-->>User: error raised
end
else status 400 and registered is true
Uploader->>Uploader: resp.raise_for_status()
Uploader-->>User: error raised
else other status handling
Uploader->>Uploader: handle other responses
end
Class diagram for updated uploader retry logicclassDiagram
class Uploader {
+upload_file(file)
-_upload_file(session, url, file, dry_run, skip_existing, registered)
-_register(session, url)
-_is_file_exists_error(resp) bool
}
class Session {
}
class Response {
+status_code int
+text str
+raise_for_status()
}
Uploader --> Session : uses
Uploader --> Response : receives from server
File-Level Changes
Tips and commands Interacting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sorry, something went wrong.
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
Please address the comments from this code review:
## Overall Comments
- The retry logic in `_upload_file` uses recursion with a boolean flag; consider replacing this with an explicit, non-recursive retry loop (e.g., a small retry counter) to make the control flow clearer and easier to extend if additional retry cases are added.
- The `registered` flag name and behavior could be clarified (e.g., `has_retried_after_register` or similar) to make it immediately obvious that it is guarding a single retry attempt rather than simply reflecting registration state.
## Individual Comments
### Comment 1
<location path="src/poetry/publishing/uploader.py" line_range="260-264" />
<code_context>
- self._register(session, url)
+ if not registered:
+ self._register(session, url)
+ return self._upload_file(
+ session, url, file, dry_run, skip_existing,
+ registered=True,
+ )
</code_context>
<issue_to_address>
**suggestion:** Forwarding all parameters positionally in the recursive call is somewhat brittle.
The retry call currently passes `dry_run` and `skip_existing` positionally. If `_upload_file`’s signature changes (new params or reordered ones), this can silently break behavior. Prefer keyword arguments for these flags and `registered` (e.g. `dry_run=dry_run`, `skip_existing=skip_existing`, `registered=True`) to make the intent explicit and avoid argument ordering issues.
```suggestion
self._register(session, url)
return self._upload_file(
session=session,
url=url,
file=file,
dry_run=dry_run,
skip_existing=skip_existing,
registered=True,
)
```
</issue_to_address>
### Comment 2
<location path="tests/publishing/test_uploader.py" line_range="233-234" />
<code_context>
+) -> None:
+ """After registering a package, the upload must be retried.
+
+ The server returns 400 "was ever registered" on the first upload,
+ then 200 on the registration and the retried upload.
+ """
+ http.post("https://foo.com", status=400, body="No package was ever registered")
</code_context>
<issue_to_address>
**suggestion (testing):** Add a complementary test for repeated 400s after registration to exercise the recursion guard
The current test only covers the case where a 400 leads to registration and then a successful retry. Please add a second test that mocks responses as: 400 (first upload), 200 (register), 400 (retried upload). That test should verify that `upload()` terminates (no further retries/registration attempts) and surfaces the second 400 (e.g., via an exception) instead of attempting to register again.
</issue_to_address>
Sorry, something went wrong.
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: Python Poetry CHANGELOG /poetry/blob/main/CHANGELOG.md — ⏳ Awaiting MergeNote: You must be authenticated to accept/decline updates. |
Sorry, something went wrong.
After _register() succeeded, resp.raise_for_status() raised on the original 400 response, so the upload was never retried. Now retries the upload once after registration, with a guard against infinite recursion if the server keeps returning 400. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
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. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
After _register() succeeded, resp.raise_for_status() raised on the original 400 response, so the upload was never retried. Now retries the upload once after registration, with a guard against infinite recursion if the server keeps returning 400.
Another from copilot. Borderline bug or enhancement, but the retry surely makes sense.
Summary by Sourcery
Ensure package uploads are retried once after successful registration when the server initially responds with a 400 indicating the package was never registered.
Bug Fixes:
Tests: