-
Notifications
You must be signed in to change notification settings - Fork 163
feat(models): deprecate implicit default provider routing #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nabinchha
merged 6 commits into
main
from
nmulepati/refactor/589-deprecate-default-provider-routing
May 5, 2026
+753
β25
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
741c278
feat(models): deprecate implicit default provider routing
nabinchha 17a48ac
fix(models): address PR #594 review feedback
nabinchha 481643f
Merge branch 'main' into nmulepati/refactor/589-deprecate-default-proβ¦
nabinchha 247fa30
fix(models): make deprecation warnings visible under default filters
nabinchha 1c7c0f8
fix(models): apply warn_at_caller to remaining deprecation sites
nabinchha a4f692f
Merge branch 'main' into nmulepati/refactor/589-deprecate-default-proβ¦
nabinchha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/data-designer-config/src/data_designer/config/utils/warning_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Helpers for emitting warnings that attribute correctly to user code. | ||
|
|
||
| Library-internal warnings (typically emitted from a pydantic ``@model_validator`` | ||
| or from a helper function) need to be attributed to the *user's* call site, not | ||
| to the library frame that happened to fire them. Two reasons: | ||
|
|
||
| 1. Attribution β a source location pointing at library internals isn't | ||
| actionable. | ||
| 2. Visibility under default filters β Python's default ``DeprecationWarning`` | ||
| filter is:: | ||
|
|
||
| default::DeprecationWarning:__main__ | ||
| ignore::DeprecationWarning | ||
|
|
||
| Library-attributed ``DeprecationWarning`` entries fall under the second | ||
| filter and are silenced. Attributing to user code is what gets the warning | ||
| actually shown. | ||
|
|
||
| 3. Deduplication β Python's once-per-location dedup key is | ||
| ``(category, module, lineno)``. When every call resolves to the same | ||
| library-internal line, every warning after the first is silently suppressed | ||
| regardless of which user file triggered it. | ||
|
|
||
| ``warn_at_caller`` walks the stack past frames whose module belongs to a known | ||
| internal package (pydantic, data_designer) and uses ``warnings.warn_explicit`` | ||
| to attribute the warning at the first user frame. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| import warnings | ||
|
|
||
| DEFAULT_INTERNAL_PREFIXES: tuple[str, ...] = ("pydantic", "pydantic_core", "data_designer") | ||
| """Modules whose frames are skipped when walking up to the user's call site. | ||
|
|
||
| Matching is exact-or-dotted-prefix (see ``_module_in_prefixes``), so | ||
| ``pydantic_helpers`` is *not* treated as part of ``pydantic``.""" | ||
|
|
||
|
|
||
| def _module_in_prefixes(module_name: str, prefixes: tuple[str, ...]) -> bool: | ||
| """Return True if ``module_name`` belongs to one of the prefix-rooted packages. | ||
|
|
||
| Uses exact-equality plus dotted-prefix matching so that, e.g., | ||
| ``pydantic_helpers`` is NOT treated as part of the ``pydantic`` package | ||
| while ``pydantic.fields`` is. Same for ``data_designer`` vs. a hypothetical | ||
| ``data_designer_other``. | ||
| """ | ||
| return any(module_name == prefix or module_name.startswith(prefix + ".") for prefix in prefixes) | ||
|
|
||
|
|
||
| def warn_at_caller( | ||
| message: str, | ||
| category: type[Warning], | ||
| *, | ||
| skip_prefixes: tuple[str, ...] = DEFAULT_INTERNAL_PREFIXES, | ||
| ) -> None: | ||
| """Emit ``message`` attributed to the first frame outside ``skip_prefixes``. | ||
|
|
||
| Intended for warnings whose root cause is the user's call site but whose | ||
| emission point is library code (a pydantic validator, an internal helper, | ||
| etc.). The walk starts above this helper's own frame and skips every frame | ||
| whose module belongs to a package in ``skip_prefixes`` until it reaches a | ||
| user frame. | ||
|
|
||
| The default skip set covers: | ||
|
|
||
| * ``pydantic`` / ``pydantic_core`` β so warnings emitted from | ||
| ``@model_validator`` callbacks escape pydantic's dispatch frames. | ||
| * ``data_designer`` β so warnings emitted from a registry / model-config | ||
| built deep inside a DataDesigner helper still attribute to the outermost | ||
| user call. Without this, attribution lands on a library file and Python's | ||
| default ``DeprecationWarning`` filter silences the warning entirely. | ||
|
|
||
| The user frame's ``__warningregistry__`` is passed to | ||
| ``warnings.warn_explicit`` so Python's built-in once-per-location dedup keys | ||
| on the *user's* (filename, lineno) rather than an internal frame. | ||
|
|
||
| We deliberately do *not* pass ``module_globals`` β it's only used for | ||
| ``linecache`` source-line display, and for scripts run with ``python -c`` | ||
| (where the user frame's ``__loader__`` is ``BuiltinImporter`` for | ||
| ``__main__``) the lookup raises ``ImportError("'__main__' is not a built-in | ||
| module")``. Skipping ``module_globals`` keeps the warning path robust at | ||
| the cost of an empty source line in the formatted output. | ||
| """ | ||
| frame = sys._getframe(1) if hasattr(sys, "_getframe") else None | ||
| while frame is not None: | ||
| module_name = frame.f_globals.get("__name__", "") | ||
| if not _module_in_prefixes(module_name, skip_prefixes): | ||
| warnings.warn_explicit( | ||
| message, | ||
| category, | ||
| frame.f_code.co_filename, | ||
| frame.f_lineno, | ||
| module=module_name, | ||
| registry=frame.f_globals.setdefault("__warningregistry__", {}), | ||
| ) | ||
| return | ||
| frame = frame.f_back | ||
|
|
||
| # Fallback: never escaped library frames (or no frame access). Use stacklevel. | ||
| warnings.warn(message, category, stacklevel=3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.