Skip to content

fix: fail with a clear RuntimeError when the provided session is closed - #218

Merged
tjorim merged 34 commits into
tjorim:mainfrom
DaanVervacke:fix/closed-session-error
Oct 21, 2026
Merged

tjorim merged 34 commits into
tjorim:mainfrom
DaanVervacke:fix/closed-session-error

Conversation

@DaanVervacke

Copy link
Copy Markdown
Contributor

Stack

Third of five stacked drafts, merge after the etag cache PR. The diff shows the earlier PRs until they merge.

Problem

A client built with an externally provided session kept using it after the caller closed it. The request then died on aiohttp's own RuntimeError: Session is closed, which names neither the cause nor the fix and appears in no docstring.

Change

_ensure_session checks session.closed and raises RuntimeError with the message "The provided session is closed, so no request can be sent". This matches the existing contract: usage errors such as invalid parameters raise standard exceptions, API and connection failures raise PyRailError subclasses. The class docstring and the README session section document the behavior.

Changelog

Fixed

  • Using a client after its provided session was closed raises a documented RuntimeError with a clear message, on both the request and the context manager path.

Testing

Two new tests: a request through a closed provided session, and entering the context manager with one. Both assert the message. All gates stay green.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a54f2aef-484a-4a95-aef3-09308858f5da
📥 Commits

Reviewing files that changed from the base of the PR and between 45d883d and f6ba2b8.

📒 Files selected for processing: 3
  • README.md
  • pyrail/irail.py
  • tests/test_irail.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DaanVervacke
DaanVervacke force-pushed the fix/closed-session-error branch from 90cb675 to 0cbcd1a Compare October 16, 2026 08:58
@DaanVervacke
DaanVervacke force-pushed the fix/closed-session-error branch from 0cbcd1a to 0b099bc Compare October 16, 2026 09:15
@DaanVervacke
DaanVervacke force-pushed the fix/closed-session-error branch from 0b099bc to c6cf210 Compare October 16, 2026 09:21
@DaanVervacke
DaanVervacke force-pushed the fix/closed-session-error branch from c6cf210 to 032efd0 Compare October 16, 2026 09:24
@tjorim
tjorim marked this pull request as ready for review October 21, 2026 12:20
@tjorim
tjorim merged commit d6a3cc8 into tjorim:main Oct 21, 2026
6 checks passed
tjorim added a commit to DaanVervacke/pyrail that referenced this pull request Oct 21, 2026
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