Skip to content

[BugFix] Format the key and class name into two error messages - #4496

Merged
theap06 merged 1 commit into
pytorch:mainfrom
David-Wu1119:fix/missing-fstring-messages
Sep 29, 2026
Merged

theap06 merged 1 commit into
pytorch:mainfrom
David-Wu1119:fix/missing-fstring-messages

Conversation

@David-Wu1119

Copy link
Copy Markdown
Contributor

Description

Two error messages in TorchRL are missing their f prefix, so they print the placeholder text instead of the value:

  • DiscreteCQLLoss.cql_loss raises KeyError: "Couldn't find the predicted qvalue with key {self.tensor_keys.pred_val} in the input tensordict. ..." when it's called before value_loss. With a custom pred_val key the user can't see which key it looked for.
  • ParallelEnv._shutdown_workers raises RuntimeError: calling {self.__class__.__name__}._shutdown_workers only allowed when env.is_closed = False.

This adds the f prefix to both.

Regression test: TestDiscreteCQL.test_dcql_cql_loss_before_value_loss in test/objectives/test_cql.py. It sets pred_val="custom_pred_val", calls cql_loss before value_loss, and checks that the KeyError names that key. The test fails on main because the message doesn't match, and passes with this change. TestDiscreteCQL passes locally: 75 tests, Python 3.12, torch 2.14, tensordict 0.14.2, CPU. I didn't add a test for the _shutdown_workers message, because it only fires on an already-closed env behind @_check_start.

Lint: pre-commit run on the three files passes (ufmt, flake8, pydocstyle, pyupgrade, codespell). I ran autoflake directly, because the hook expects it on PATH: no issues.

Fixes #4495

Generated with Claude Code

DiscreteCQLLoss.cql_loss and ParallelEnv._shutdown_workers built their
error messages without an f-prefix, so users saw the literal
"{self.tensor_keys.pred_val}" and "{self.__class__.__name__}".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 03:17
@pytorch-bot

pytorch-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4496

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 16 Awaiting Approval

As of commit 9b56110 with merge base 71a4143 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coder-jayp coder-jayp left a comment

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.

LGTM. Thanks for the fix. The regression test properly asserts the observable behavior.

@theap06
theap06 merged commit 0d39a0c into pytorch:main Sep 29, 2026
141 of 146 checks passed
bsprenger pushed a commit that referenced this pull request Oct 9, 2026
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugFix CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Objectives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Two error messages print their placeholders instead of the values

4 participants