fix: correct flow operator detection in _module.py (closes #2280) - #3162
fix: correct flow operator detection in _module.py (closes #2280)#3162botbikamordehai2-sketch wants to merge 1 commit into
Conversation
📝 WalkthroughSummary
Walkthrough
ChangesFlow operator detection
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 74e7d296-82c2-450e-9aef-57c94fb7480d
📒 Files selected for processing (1)
packages/dbgpt-core/src/dbgpt/util/cli/_module.py
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Use Python 3.10 or newer for project development.
Files:
packages/dbgpt-core/src/dbgpt/util/cli/_module.py
packages/dbgpt-core/src/dbgpt/**/*.py
⚙️ CodeRabbit configuration file
packages/dbgpt-core/src/dbgpt/**/*.py: 这是以 dbgpt 名义发布的核心库。
- 严格审查公共 API、构造函数参数、返回类型、Pydantic 字段、序列化格式和异常语义的向后兼容性。
- 不得引入或扩大 core 对 dbgpt_ext、dbgpt_serve、dbgpt_app、dbgpt_client 或
dbgpt_sandbox 的反向依赖。只报告当前 diff 新增或扩大的依赖违规问题。- 对于 AWEL 变更,应同时审查同步、异步和流式执行路径。检查 DAG 关系、
ContextVar 传播、背压、顺序、结束信号、异常传播和取消处理。- 不得在 async 函数中直接执行阻塞式数据库、文件、网络或模型操作。检查连接、
task、thread、generator 和临时资源的清理。- 公共行为变更必须提供邻近的回归测试,并覆盖相关的正常、错误、空输入、并发、
取消或流式场景。
Files:
packages/dbgpt-core/src/dbgpt/util/cli/_module.py
🪛 Ruff (0.15.21)
packages/dbgpt-core/src/dbgpt/util/cli/_module.py
[warning] 23-23: Do not catch blind exception: Exception
(BLE001)
| try: | ||
| metadata = getattr(cls, "metadata", None) | ||
| if metadata is None: | ||
| return False | ||
| # For class-level properties or descriptors, get the actual metadata object | ||
| if callable(metadata): | ||
| metadata = metadata() | ||
| return issubclass(cls, BaseOperator) and isinstance(metadata, ViewMetadata) | ||
| except Exception: | ||
| return False |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add regression tests for metadata resolution.
Cover normal ViewMetadata, callable providers, missing/invalid metadata, providers that raise, unrelated classes with callable metadata, and the full _scan_awel_flow path.
As per path instructions, “公共行为变更必须提供邻近的回归测试,并覆盖相关的正常、错误、空输入、并发、取消或流式场景。”
🧰 Tools
🪛 Ruff (0.15.21)
[warning] 23-23: Do not catch blind exception: Exception
(BLE001)
Source: Path instructions
| metadata = getattr(cls, "metadata", None) | ||
| if metadata is None: | ||
| return False | ||
| # For class-level properties or descriptors, get the actual metadata object | ||
| if callable(metadata): | ||
| metadata = metadata() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Check BaseOperator before invoking metadata.
_scan_awel_flow uses base_class=object, so this predicate runs for every discovered class. Lines [20]-[21] invoke any callable metadata before confirming that cls is a BaseOperator; an unrelated class with a no-argument metadata method can therefore execute during startup. Move the subclass check ahead of metadata resolution.
| if callable(metadata): | ||
| metadata = metadata() | ||
| return issubclass(cls, BaseOperator) and isinstance(metadata, ViewMetadata) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Reuse the resolved metadata downstream.
For callable cls.metadata, this helper returns True after resolving a ViewMetadata, but _scan_awel_flow later reads cls.metadata directly at Line [50], so it receives the callable and .parameters raises. It also re-evaluates the provider at Line [70]. Return or cache the resolved metadata and reuse the same object for extraction and classification.
|
Thanks for the contribution! This change is behavior-neutral for existing flow operators (no regression), but two things to confirm:
|
What
The
_is_flow_operatorfunction indbgpt/util/cli/_module.pyincorrectly identified flow operators whencls.metadatawas a property or descriptor rather than a directViewMetadatainstance. This caused AWEL flow scanning to fail, leading to database schema errors (no such table: gpts_app_collection) during server startup.Fix
Updated
_is_flow_operatorto safely retrieve metadata viagetattr, handle callable properties, and wrap the check in a try-except for robustness. This ensures correct classification of flow operators and resources.Closes #2280