feat: add MaaSModelRef resource and deprecate MaaSModel for backward compatibility#2669
Conversation
WalkthroughTwo changes modernize MAAS model handling: a deprecation warning is added to MaaSModel directing users to MaaSModelRef, and a new NamespacedResource subclass MaaSModelRef is introduced with initialization and dictionary conversion logic including validation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
/lgtm |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ocp_resources/maa_s_model.py (1)
10-15: Module-level deprecation warning fires on every import, even if class is never used.This warning triggers at import time, which can be noisy in codebases that import this module transitively. Consider moving the deprecation warning into
__init__so it only fires when someone actually instantiatesMaaSModel.Additionally, this modification appears to be within the generated code region (between lines 1 and 52). Per coding guidelines, changes to generated code should be made via the generator tool instead.
♻️ Suggested: Move warning to __init__ for targeted deprecation
-from warnings import warn - from ocp_resources.exceptions import MissingRequiredArgumentError from ocp_resources.resource import NamespacedResource -warn( - "MaaSModel is deprecated and will be removed in a future release. " - "Please use `MaaSModelRef` from maas_model_ref.py instead.", - DeprecationWarning, - stacklevel=2, -) - class MaaSModel(NamespacedResource): """ MaaSModel is the Schema for the maasmodels API """ api_group: str = NamespacedResource.ApiGroup.MAAS_OPENDATAHUB_IO def __init__( self, model_ref: dict[str, Any] | None = None, **kwargs: Any, ) -> None: r""" Args: model_ref (dict[str, Any]): ModelRef references the actual model endpoint """ + from warnings import warn + warn( + "MaaSModel is deprecated and will be removed in a future release. " + "Please use `MaaSModelRef` from maas_model_ref.py instead.", + DeprecationWarning, + stacklevel=2, + ) super().__init__(**kwargs)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ocp_resources/maa_s_model.py` around lines 10 - 15, The module-level DeprecationWarning call (warn(...)) fires on every import; move that warning into the MaaSModel.__init__ method so the deprecation only logs when an instance is created (reference symbols: warn, DeprecationWarning, MaaSModel, __init__). Do not directly modify the generated-code region (the existing warn call sits inside the generated block); instead update the generator/template that produces this file so the warn invocation is emitted inside the MaaSModel.__init__ body (or add a check in __init__ to call warn once), ensuring the warning is not triggered at import time.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ocp_resources/maa_s_model.py`:
- Around line 10-15: The module-level DeprecationWarning call (warn(...)) fires
on every import; move that warning into the MaaSModel.__init__ method so the
deprecation only logs when an instance is created (reference symbols: warn,
DeprecationWarning, MaaSModel, __init__). Do not directly modify the
generated-code region (the existing warn call sits inside the generated block);
instead update the generator/template that produces this file so the warn
invocation is emitted inside the MaaSModel.__init__ body (or add a check in
__init__ to call warn once), ensuring the warning is not triggered at import
time.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: de10666f-9bec-4916-8b0b-1914ed586281
⛔ Files ignored due to path filters (2)
class_generator/schema/__resources-mappings.json.gzis excluded by!**/*.gz,!class_generator/schema/**class_generator/schema/_definitions.jsonis excluded by!class_generator/schema/**
📒 Files selected for processing (2)
ocp_resources/maa_s_model.pyocp_resources/maas_model_ref.py
|
/verified |
|
/check-can-merge |
…compatibility
Short description:
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:
Summary by CodeRabbit
New Features
Deprecations