Skip to content

fix: Workflow debugging for authorized applications will result in an error message indicating unauthorized access to the model #2819

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
merged 1 commit into from
Apr 8, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow debugging for authorized applications will result in an error message indicating unauthorized access to the model

… error message indicating unauthorized access to the model
Copy link

f2c-ci-robot bot commented Apr 8, 2025

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.

Copy link

f2c-ci-robot bot commented Apr 8, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 1a704f1 into main Apr 8, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow branch April 8, 2025 02:51
const submitObj = {
work_flow: obj.work_flow
work_flow: obj.work_flow,
user_id: obj.user
}
return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
chartOpenId.value = res.data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one issue in the given code that could cause problems if obj doesn't have a property named work_flow. The error would occur because of accessing .work_flow on submitObj, assuming it exists.

To prevent this from causing errors, you should add conditions to ensure both properties (work_flow and user) exist before constructing the submitObj.

Here’s an optimized version with these changes:

const openChatId: () => Promise<string> = () => {
  if (isWorkFlow(obj.type)) {
    // Check if work_flow and user exist
    if (typeof obj.work_flow === 'string' && typeof obj.user !== 'undefined') {
      const submitObj = {
        work_flow: obj.work_flow,
        user_id: obj.user
      };
      return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
        chartOpenId.value = res.data;
      });
    } else {
      throw new Error('Missing required fields: work_flow or user');
    }
  } else {
    // ...
  }
}

With this modification, we first check if obj.work_flow exists as a string using typeof ("string"), and verify that obj.user does not equal undefined. If either condition fails, an error is thrown with a descriptive message. This prevents potential runtime errors and makes your function safer and more robust.

@@ -97,7 +97,7 @@ class OpenWorkFlowTemp(APIView):
tags=[_("Application/Chat")])
def post(self, request: Request):
return result.success(ChatSerializers.OpenWorkFlowChat(
data={**request.data, 'user_id': request.user.id}).open())
data={'user_id': request.user.id, **request.data}).open())

class OpenTemp(APIView):
authentication_classes = [TokenAuth]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has a few issues:

  1. In OpenWorkFlowTemp.post(), the serializer is instantiated with extra arguments (data), which might be unnecessary if they are not used in the serialization process.

  2. The method is using kwargs, but there's no use of unpacking them into the serializer. This can be simplified without affecting the functionality.

Here’s an updated version that addresses these points:

class OpenWorkFlowTemp(APIView):
    @action(detail=False, methods=['post'], url_name='chat-list', name=_('Application/Chat'), authentication_classes=[],
            permission_classes=[], tags=[_("Application/Chat")])
    def post(self, request: Request):
        chat_data = {'user_id': request.user.id}
        # Merge other data from the request.POST (if needed)
        chat_data.update(request.data)
        
        # Create the serialized object and open it
        return result.success(ChatSerializer.OpenWorkFlowChat(data=chat_data).open())

class OpenTemp(APIView):
    authentication_classes = [TokenAuth]

Changes made:

  1. Simplified the instantiation of the serializer to pass just 'user_id'.
  2. Removed the unnecessary dictionary spread operator before request.data.

These changes should resolve the potential issue and make the code cleaner. If you have additional requirements or need further modifications, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant