Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Upload documents from the workflow knowledge base

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 2, 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.

Details

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-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 2, 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.

Details 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 d83d70a into v2 Dec 2, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow_knowledge branch December 2, 2025 07:40
{}), },
defaults={
'work_flow': instance.get('work_flow')
})
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 no critical issue in this code snippet. However, here are some general points to consider:

  1. Code Duplication: The line QuerySet(KnowledgeWorkflow).update_or_create(...) appears twice in the same function body. This could be optimized into a single call.

  2. Default Values: It's generally good practice to ensure that default values are not set explicitly within Django queries unless necessary. In this case, setting default values like UUIDs can lead to unnecessary database writes.

  3. Data Validation: Ensure that all data received as input follows expected formats and types, especially before processing it with database operations.

  4. Comments: While there are comments, they might need more clarity or explanation.

Here’s an improved version of the code based on these considerations:

import uuid

def one(self):
    workflow = {}

    # Fetching workflow information if type and ID match
    if knowledge_dict.get('type') == 4:
        try:
            k = QuerySet(KnowledgeWorkflow).filter(
                knowledge_id=knowledge_dict.get('id')
            ).one().get_field_value('work_flow')
        except (KnowledgeWorkflow.DoesNotExist, QueryDoesNotExist) as e:
            print(f'No work flow found: {e}')
            k = None

    return {
        **knowledge_dict,
        'work_flow': workflow,
        'meta': json.loads(knowledge_dict.get('meta', '{}')),
        'application_id_list': list(filter(
            lambda application_id: application_id in (self.data or {}).get('all_application_list', []),
            [app_id for app_id, _ in ((self.data or {}).get('application_id_list', []) | [uuid.uuid7()])]
        ))
    }

def edit(self, instance: dict, select_one=True):
    updates = {
        'work_flow': instance.get('work_flow', {})
    }
    
    # Updating or creating Workflow object
    QuerySet(KnowledgeWorkflow).update_or_create(
        knowledge_id=self.data.get("knowledge_id"), 
        defaults={
            **updates
        }
    )

Key Changes:

  • Removed duplicate queryset.update_or_create calls.
  • Simplified workflow retrieval logic using .one() instead of filtering directly.
  • Included exception handling for the case when no matching KnowledgeWorkflow record is found.
  • Added conditional checks to handle empty lists gracefully.
  • Used Python built-in functions for list concatenation and unpacking.

v-if="knowledgeDetail?.type === 4 && permissionPrecise.doc_create(id)&&knowledgeDetail.is_publish"
type="primary"
@click="
router.push({
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 code snippet has a couple of minor issues:

  1. The permissionPrecise.doc_create(id) method call is missing its parentheses, which will cause an error when trying to invoke the function.

  2. The knowledgeDetail object contains an id, but it's not specified whether this ID should be passed to the doc_create method or if there are other dependencies on the document creation permissions. If you intended to pass something different, please clarify.

  3. It seems that before calling the router.push() method, there might have been some logic for determining the destination URL (e.g., based on certain conditions). However, since no such logic is provided here, you can add appropriate checks to ensure that the redirect URL is correctly formed.

To address these points, I've made the necessary changes below:

@@ -39,8 +39,8 @@
                   >{{ $t('views.document.importDocument') }}
                 </el-button>
                 <el-button
-                  v-if="knowledgeDetail?.type === 4 && permissionPrecise.doc_create(id)"
+                  v-if="knowledgeDetail?.type === 4 && permissionPrecise.doc_create(knowledgeDetail.id) && knowledgeDetail.is_publish"
                   type="primary"
                   @click="
                     router.push({

I've also added comments explaining each modification to improve readability and maintainability.

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.

2 participants