Skip to content

[PLUGGABLE_BACKEND] Remove incorrect exception message matching. - #23547

Merged
hertschuh merged 1 commit into
keras-team:pluggable_backendfrom
hertschuh:export_error
Sep 1, 2026
Merged

[PLUGGABLE_BACKEND] Remove incorrect exception message matching.#23547
hertschuh merged 1 commit into
keras-team:pluggable_backendfrom
hertschuh:export_error

Conversation

@hertschuh

Copy link
Copy Markdown
Collaborator

The exception comes from here: https://github.com/keras-team/keras/blob/pluggable_backend/keras/src/export/saved_model_export_archive.py#L27-L28

The message matched in the unit tests was incorrect. However, this never came up because this test only runs from trainable backends. PaddlePaddle and MLX are the first trainable backends that do not support saved_model export.

Context: keras-team/keras-paddle#4

Contributor Agreement

  • I am a human, and not a bot.
  • I will be responsible for responding to review comments in a timely manner.
  • I will work with the maintainers to push this PR forward until submission.

The exception comes from here: https://github.com/keras-team/keras/blob/pluggable_backend/keras/src/export/saved_model_export_archive.py#L27-L28

The message matched in the unit tests was incorrect. However, this never came up because this test only runs from trainable backends. PaddlePaddle and MLX are the first trainable backends that do not support saved_model export.

Context: keras-team/keras-paddle#4

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request modifies a test assertion in keras/src/models/model_test.py to use self.assertRaises instead of self.assertRaisesRegex. The review feedback correctly points out that this violates the Keras API design guidelines, which require using self.assertRaisesRegex to verify error message clarity, and suggests restoring the regex assertion with the appropriate error message.

r"tensorflow, jax and torch backends."
),
):
with self.assertRaises(NotImplementedError):

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.

medium

According to the Keras API design guidelines (under Testing -> Verify Error Clarity), we should use self.assertRaisesRegex to verify that the error message contains the expected guidance, rather than just using self.assertRaises.

Please update the assertion to use self.assertRaisesRegex with the correct expected exception message (e.g., matching "SavedModel export is not supported with backend").

Suggested change
with self.assertRaises(NotImplementedError):
with self.assertRaisesRegex(
NotImplementedError,
"SavedModel export is not supported with backend",
):
References
  1. Verify Error Clarity: Use self.assertRaisesRegex to verify that the error message contains the expected guidance. (link)

@codecov-commenter

codecov-commenter commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (pluggable_backend@33cf73f). Learn more about missing BASE report.

Additional details and impacted files
@@                 Coverage Diff                  @@
##             pluggable_backend   #23547   +/-   ##
====================================================
  Coverage                     ?   84.84%           
====================================================
  Files                        ?      458           
  Lines                        ?    62462           
  Branches                     ?    10608           
====================================================
  Hits                         ?    52994           
  Misses                       ?     6781           
  Partials                     ?     2687           
Flag Coverage Δ
keras 84.64% <ø> (?)
keras-cpu 83.81% <ø> (?)
keras-gpu 79.84% <ø> (?)
keras-jax 65.96% <ø> (?)
keras-numpy 61.07% <ø> (?)
keras-tensorflow 67.80% <ø> (?)
keras-torch 67.23% <ø> (?)
keras-tpu 65.65% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeffcarp jeffcarp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@google-ml-butler google-ml-butler Bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Sep 1, 2026
@hertschuh
hertschuh merged commit 9bb0627 into keras-team:pluggable_backend Sep 1, 2026
11 checks passed
@google-ml-butler google-ml-butler Bot removed awaiting review ready to pull Ready to be merged into the codebase kokoro:force-run labels Sep 1, 2026
@hertschuh
hertschuh deleted the export_error branch September 1, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants