Skip to content

Add DeprecationError exception and migrate raise DeprecationWarning usages#5224

Open
saitcakmak wants to merge 1 commit into
facebook:mainfrom
saitcakmak:export-D107660126
Open

Add DeprecationError exception and migrate raise DeprecationWarning usages#5224
saitcakmak wants to merge 1 commit into
facebook:mainfrom
saitcakmak:export-D107660126

Conversation

@saitcakmak
Copy link
Copy Markdown
Contributor

Summary:
Introduce DeprecationError(AxError) in ax/exceptions/core.py for hard-break deprecations where accessing a removed/deprecated API should fail immediately with an actionable message.

raise DeprecationWarning(...) is semantically incorrect: DeprecationWarning is a warning category, not an exception type. Raising it (a) does not interoperate with warnings.catch_warnings() / simplefilter("ignore", DeprecationWarning) -- it still crashes -- and (b) violates the Ax team rule that runtime errors should be raised from ax/exceptions types. This diff adds a dedicated error class for that purpose and migrates the existing in-repo raise DeprecationWarning sites to it:

  • ax/service/utils/scheduler_options.py (SchedulerOptions)
  • ax/adapter/pairwise.py (PairwiseAdapter)
  • ax/core/batch_trial.py (_status_quo_weight_override)
  • ax/fb/service/ax_batch_client.py (attach_batch_trial)

For soft deprecations that should still work with a notice, continue to use warnings.warn(..., DeprecationWarning) -- this error is only for hard breaks.

This is a prerequisite for migrating RangeParameter.digits (in a stacked diff) off raise DeprecationWarning.

Differential Revision: D107660126

…sages

Summary:
Introduce `DeprecationError(AxError)` in `ax/exceptions/core.py` for hard-break deprecations where accessing a removed/deprecated API should fail immediately with an actionable message.

`raise DeprecationWarning(...)` is semantically incorrect: `DeprecationWarning` is a warning *category*, not an exception type. Raising it (a) does not interoperate with `warnings.catch_warnings()` / `simplefilter("ignore", DeprecationWarning)` -- it still crashes -- and (b) violates the Ax team rule that runtime errors should be raised from `ax/exceptions` types. This diff adds a dedicated error class for that purpose and migrates the existing in-repo `raise DeprecationWarning` sites to it:

- `ax/service/utils/scheduler_options.py` (SchedulerOptions)
- `ax/adapter/pairwise.py` (PairwiseAdapter)
- `ax/core/batch_trial.py` (`_status_quo_weight_override`)
- `ax/fb/service/ax_batch_client.py` (`attach_batch_trial`)

For *soft* deprecations that should still work with a notice, continue to use `warnings.warn(..., DeprecationWarning)` -- this error is only for hard breaks.

This is a prerequisite for migrating `RangeParameter.digits` (in a stacked diff) off `raise DeprecationWarning`.

Differential Revision: D107660126
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 5, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Jun 5, 2026

@saitcakmak has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107660126.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.55%. Comparing base (873933b) to head (7001050).

Files with missing lines Patch % Lines
ax/adapter/pairwise.py 0.00% 2 Missing ⚠️
ax/service/utils/scheduler_options.py 0.00% 2 Missing ⚠️
ax/core/batch_trial.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5224      +/-   ##
==========================================
- Coverage   96.57%   96.55%   -0.02%     
==========================================
  Files         619      619              
  Lines       70140    70143       +3     
==========================================
- Hits        67735    67729       -6     
- Misses       2405     2414       +9     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants