-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Knowledge Base Workflow Execution List #4437
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,15 +61,15 @@ def list(self, instance: Dict, is_valid=True): | |
| self.is_valid(raise_exception=True) | ||
| KnowledgeWorkflowActionListQuerySerializer(data=instance).is_valid(raise_exception=True) | ||
| return [{'id': a.id, 'knowledge_id': a.knowledge_id, 'state': a.state, | ||
| 'details': a.details, 'meta': a.meta, 'run_time': a.run_time} for a in self.get_query_set(instance)] | ||
| 'meta': a.meta, 'run_time': a.run_time} for a in self.get_query_set(instance)] | ||
|
|
||
| def page(self, current_page, page_size, instance: Dict, is_valid=True): | ||
| if is_valid: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your code looks mostly clean and well-formatted. However, there are a couple of minor improvements and suggestions:
Here's a slightly improved version of your code with some of these considerations: @@ -61,15 +61,18 @@ def list(self, instance: Dict, is_valid=True) -> List[Dict]:
self.is_valid(raise_exception=True)
KnowledgeWorkflowActionListQuerySerializer(data=instance).is_valid(raise_exception=True)
return [
- {'id': a.id, 'knowledge_id': a.knowledge_id, 'state': a.state,
+ {
'id': a.id,
'knowledge_id': a.knowledge_id,
'state': a.state,
- 'details': a.details, 'meta': a.meta, 'run_time': a.run_time}
+ 'meta': a.meta,
+ 'run_time': a.run_time
+ }
for a in self.fetch_actions(instance)
]
def fetch_actions(self, instance: Dict) -> Iterable[KnowledgeWorkflowAction]:
"""Fetches actions from the database."""
# Example implementation using Django ORM
return (
KnowledgeWorkflowAction.objects.filter(knowledge_id=instance['knowledge_id'])
.order_by('created_at')
)
@@ -77,7 +80,7 @@ def page(self, current_page: int, page_size: int, instance: Dict, is_valid=True) \
raise CustomException("Invalid data provided")
result = page_search(
current_page=current_page,
page_size=page_size,
items=self.fetch_actions(instance),
item_serializer=lambda a: {
'id': a.id,
'knowledge_id': a.knowledge_id,
'state': a.state,
- 'details': a.details,
+ 'metadata': a.metadata,
'meta': a.meta,
'run_time': a.run_time
}
@@ -102,6 +105,7 @@ def action(self, instance: Dict, user, with_valid=True):
if with_valid:
self.validate_action_data(instance)
+# Assuming CustomException is defined somewhere else in your project
class CustomException(Exception):
passThese modifications improve clarity and potentially add robustness, though without additional context about your application and its requirements, further optimizations may be necessary specific to your use-case. |
||
| self.is_valid(raise_exception=True) | ||
| KnowledgeWorkflowActionListQuerySerializer(data=instance).is_valid(raise_exception=True) | ||
| return page_search(current_page, page_size, self.get_query_set(instance), | ||
| lambda a: {'id': a.id, 'knowledge_id': a.knowledge_id, 'state': a.state, | ||
| 'details': a.details, 'meta': a.meta, 'run_time': a.run_time}) | ||
| 'meta': a.meta, 'run_time': a.run_time}) | ||
|
|
||
| def action(self, instance: Dict, user, with_valid=True): | ||
| if with_valid: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ | |
| from common.constants.permission_constants import PermissionConstants, RoleConstants, ViewPermission, CompareConstants | ||
| from common.log.log import log | ||
| from common.result import result, DefaultResultSerializer | ||
| from knowledge.api.knowledge_workflow import KnowledgeWorkflowApi, KnowledgeWorkflowActionApi | ||
| from knowledge.api.knowledge_workflow import KnowledgeWorkflowApi, KnowledgeWorkflowActionApi, \ | ||
| KnowledgeWorkflowActionPageApi | ||
| from knowledge.serializers.common import get_knowledge_operation_object | ||
| from knowledge.serializers.knowledge_workflow import KnowledgeWorkflowSerializer, KnowledgeWorkflowActionSerializer, \ | ||
| KnowledgeWorkflowMcpSerializer | ||
|
|
@@ -118,7 +119,7 @@ class Page(APIView): | |
| summary=_('Page Knowledge workflow action'), | ||
| operation_id=_('Page Knowledge workflow action'), # type: ignore | ||
| parameters=KnowledgeWorkflowActionApi.get_parameters(), | ||
| request=KnowledgeWorkflowActionApi.get_request(), | ||
| request=KnowledgeWorkflowActionPageApi.get_request(), | ||
| responses=KnowledgeWorkflowActionApi.get_response(), | ||
| tags=[_('Knowledge Base')] # type: ignore | ||
| ) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No significant errors or critical issues were found in the modified code snippet. Here is a brief overview of what was checked and updated:
Overall, the update seems straightforward without introducing bugs or significant performance optimizations. If there are ongoing maintenance tasks that need attention, this might be a good place for future modifications based on feedback or changes in requirements. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet is mostly clear and follows Python conventions. However, there are several areas that could be improved or optimized:
Imports: The imports are fine but consider using an alias if
APIMixinbecomes longer.Docstrings: Ensure that all classes have a docstring to describe their purpose, methods should also have concise descriptions.
Static Methods: Using static methods when they don't need access to instance attributes can simplify the code structure. Consider making these into regular methods without
@staticmethod.Class Names and Variable Names: Use meaningful names for variables and ensure consistency across the class hierarchy (e.g., camelCase instead of snake_case).
Here's a revised version with some minor improvements:
Key Changes:
cls.KNOWLEDGE_WORKFLOW_ACTION_*) insideget_requestmethods. Make sure this constant is defined somewhere in one of these classes or elsewhere in your project. If not, define it properly at global scope.