Skip to content

fix(auth): correctly parse --expiration duration values#1148

Merged
stevemessick merged 2 commits into
Kaggle:mainfrom
sridipbasu:fix/auth-expiration-duration-parsing
Jul 24, 2026
Merged

fix(auth): correctly parse --expiration duration values#1148
stevemessick merged 2 commits into
Kaggle:mainfrom
sridipbasu:fix/auth-expiration-duration-parsing

Conversation

@sridipbasu

Copy link
Copy Markdown
Contributor

Summary

The --expiration option in kaggle auth print-access-token was not parsing duration values correctly. Inputs like 6h, 2d, and 30s caused an uncaught TypeError because the duration suffix was passed directly to relativedelta() as a single-letter keyword. The CLI also advertised formats like 2:30 and 2h30s, even though they were not actually supported.

Fix

  • Mapped short duration suffixes (s, m, h, d, w) to the correct relativedelta keyword arguments.
  • Improved validation so invalid inputs now return a friendly ValueError instead of a Python traceback.
  • Updated the CLI help text, method docstring, and documentation to reflect the formats that are actually supported.

Tests

Added regression tests to verify that:

  • 30s, 5m, 6h, 2d, and 2w parse correctly.
  • Invalid inputs (2:30, 2h30s, 6x, 0h, etc.) raise a friendly ValueError.
  • The parser no longer raises the uncaught TypeError.
  • Existing CLI-related tests continue to pass.

Ran:

pytest tests/unit/test_parse_duration.py
pytest tests/unit/test_cli_commands.py

@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

@stevemessick

Copy link
Copy Markdown
Contributor

@sridipbasu It looks like we still need the comment to disable type checking for the call to relativedelta() on line 1674: # type: ignore[arg-type]. I think that is why the lint check fails. (Excuse me for jumping in before you're ready for a review)

@sridipbasu

Copy link
Copy Markdown
Contributor Author

Thanks @stevemessick for catching that!

You're right. While refactoring _parse_duration(), I kept the relativedelta(**{unit: value}) call but accidentally removed the original # type: ignore[arg-type] comment.

Since mypy uses the types-python-dateutil stubs, it can't infer the dynamically constructed keyword arguments passed to relativedelta(), so it reports the arg-type error that showed up in the lint job.

I've added the suppression back on the relativedelta() call. I also reproduced the lint failure locally with the dateutil stubs installed, confirmed that it disappears after restoring the comment, and verified that black and the relevant unit tests still pass.

@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

@stevemessick
stevemessick merged commit fa7f9f4 into Kaggle:main Jul 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants