-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix: Application deleted, workflow page error reported #2743
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -288,7 +287,7 @@ const update_field = () => { | |||
} | |||
}) | |||
.catch((err) => { | |||
// set(props.nodeModel.properties, 'status', 500) | |||
set(props.nodeModel.properties, 'status', 500) | |||
}) | |||
} | |||
|
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 seems to be JavaScript with React/Vue syntax (since it includes this.$t
, set
). The changes look generally correct, but here are a few things that could be improved:
-
Simplify the Line: In both occurrences of
{{ $t('views.applicationWorkflow.nodes.aiChatNode.returnContent.label') }}
, you can replace single-line HTML comments with template literals or remove them completely if they're just placeholders.<div class="mr-4">Return content label</div> // Remove these lines if not needed <!-- <span>{{ $t('views.applicationWorkflow.nodes.aiChatNode.returnContent.label') }}</span> -->
-
Avoid Redundancy: There's a redundant comment on the same line where you set an error status, though this might be intentional depending on the context.
-
Code Structure: Ensure that all functions and logic adhere to best practices. This particular piece looks fine for updating properties and handling errors, but general code structure is recommended for clarity.
const update_field = () => {
axios.post(`/api/nodes/${props.id}/update-field`, { ... }).then(
(res) => {}
).catch((err) => {
set(props.nodeModel.properties, 'status', 500);
});
};
This should cover most minor improvements and ensure readability.
@@ -1332,4 +1334,3 @@ async def get_mcp_tools(servers): | |||
} | |||
for tool in asyncio.run(get_mcp_tools({server: servers[server]}))] | |||
return tools | |||
|
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.
There are a few issues and improvements that can be made to the code:
-
Use of
QuerySet.first()
: The use offilter().first()
is generally preferred overget()
because it won't raise an exception if no record is found; instead, it returnsNone
. This makes the function more robust. -
Explicitly Handle Not Found Case: Instead of catching exceptions, you should explicitly handle the case where
embed_application
isNone
, which could happen if no application exists with the given ID. -
Optimization on Server List: In the
get_mcp_tools
asynchronous generator function, there is unnecessary double iteration on the server dictionary when usingasyncio.wait()
. You might need to rethink how this part handles the server list.
Here's the improved code:
def get_application(self, app_id, with_valid=True):
if self.is_valid(raise_exception=True) and with_valid:
embed_application = QuerySet(Application).filter(id=app_id).first()
if embed_application is None:
raise AppApiException(500, _('Application does not exist'))
if embed_application.type == ApplicationTypeChoices.WORK_FLOW:
work_flow_version = (
QuerySet(WorkFlowVersion)
.filter(application_id=embed_application.id)
.order_by('-create_time')
.first()
)
# Further processing...
# Other parts remain unchanged.
For the get_mcp_tools
function, consider refactoring to avoid double iteration:
async def get_mcp_tools(servers: Dict[str, dict]) -> Generator[MCPToolResponse, Literal[''], str]:
for server in servers.keys():
await asyncio.sleep(0) # Yield control between iterations
response = {}
try:
mcp_server_response = await run_in_threadpool(cast(MCPRunResponse, call_mcpe_api(method='info', data={})))
if 'players_count' in mcp_server_response:
response['current_players'] = mcp_server_response.get('players_count')
if response:
yield MCPToolResponse(tool_type="SERVER_INFO", tool_name=f"info_{server}", details=response)
except Exception as e:
Logger.error(f'MPC Tool Info Error from `{server}` : {e}')
In the revised version, I've added a try-except
block within each server loop, which helps in handling any errors gracefully without crashing the entire generator. Additionally, I used cast()
to type-check mcp_server_response
, although based on typical usage, it is already castable to MCPRunResponse
.
fix: Application deleted, workflow page error reported