Nishuuzz opened a new pull request, #55270:
URL: https://github.com/apache/arrow/pull/55270
### Rationale for this change
`archery crossbow notify-token-expiration` cannot run. It builds its report
with
```python
email_report = TokenExpirationEmailReport(report)
```
but `TokenExpirationEmailReport.__init__` is `def __init__(self, **kwargs)`,
so that raises
```
TypeError: TokenExpirationEmailReport.__init__() takes 1 positional argument
but 2 were given
```
The construction happens before the `if send:` branch, so `--send` and the
dry-run both fail the same way, even with every option supplied.
Writing it as `TokenExpirationEmailReport(report=report)` is not enough
either. `EmailReport.fields` lists `report`, `sender_name`, `sender_email` and
`recipient_email`, and `Report.__init__` raises `ValueError: Missing keyword
argument sender_name` for anything absent. Those three are what
`EmailReport.render()` uses to set the `From` and `To` headers, and
`ReportUtils.send_email()` holds no addresses of its own — it hands the
rendered message to `smtplib`, which takes the recipients from the headers. So
the command's `--sender-name`, `--sender-email` and `--recipient-email` options
genuinely have to reach the report, and at the moment none of them do.
This came in with 288cd43bdc (GH-48623, #48624, first released in 24.0.0),
which introduced the `TokenExpirationEmailReport` subclass and replaced
```python
email_report = EmailReport(
report=TokenExpirationReport(
token_expiration_date or "ALREADY_EXPIRED", days_left),
sender_name=sender_name,
sender_email=sender_email,
recipient_email=recipient_email
)
```
with the positional call. The sibling `nightly-report` command was converted
in the same commit and still passes all four keyword arguments, so this is the
only command affected — I checked that one rather than assume.
Nothing in the repository invokes `notify-token-expiration`, which is
presumably why it went unnoticed. Worth noting that GH-48861 (6ec91627ec)
already had to fix `smtplib.SMTP.send_message` usage from the same refactor;
that fix referenced `report.recipient_email`, which is the shape this restores.
It was only ever reachable through `nightly-report`, since this path dies
earlier.
Closes #55269.
### What changes are included in this PR?
Pass `report`, `sender_name`, `sender_email` and `recipient_email` to
`TokenExpirationEmailReport` as keyword arguments, matching how
`nightly-report` constructs `NightlyEmailReport`. One call site; no change to
`EmailReport` or `send_email`.
### Are these changes tested?
Yes, a new `test_crossbow_notify_token_expiration` in
`archery/crossbow/tests/test_crossbow_cli.py`. It stubs out `Queue` and `Repo`
so it needs no git repository or network, runs the command through `CliRunner`
on the dry-run path, and asserts on the rendered `From` and `To` headers —
checking the options actually arrive rather than only that the command stopped
crashing.
What I ran locally:
- The new test fails on unmodified `main` with exactly the reported
`TypeError`, and passes with the change.
- Reproduced the three construction cases directly to be sure of the second
failure mode too: positional gives the `TypeError`, `report=report` alone gives
`ValueError: Missing keyword argument sender_name`, and all four keywords
construct fine.
- Full `archery` run before and after, excluding three modules needing
optional deps I don't have installed: 26 failed / 24 passed / 1 skipped before,
26 failed / 25 passed / 1 skipped after. The 26 are pre-existing `docker`
`FileNotFoundError`s on this machine; the delta is exactly the one new test.
- `flake8 --config python/setup.cfg` clean on both files.
I did not send a real e-mail, so the SMTP path itself is still only
exercised as far as `send_email()`.
### Are there any user-facing changes?
`archery crossbow notify-token-expiration` works again and its
sender/recipient options take effect. No other command changes.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
Found with a static scan for parameters a function accepts and never reads,
which flagged `sender_name`, `sender_email` and `recipient_email` here. The
code, test and this description were AI-assisted; the history above was read
from the commits rather than guessed, and the verification steps listed were
actually run.
**PR code and description written by:**
- [ ] Human
- [x] AI
**Reviewed before submission by:**
- [ ] Human
- [x] AI
- [ ] Not reviewed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]