Skip to content

Conversation

@xgopilot
Copy link
Contributor

@xgopilot xgopilot bot commented Dec 17, 2025

Requested by @nighca

This PR fixes issue #177 where the keys field in prefop result items was not being correctly returned.

Summary

When a prefop operation (e.g., vsample) generates multiple files, the HTTP response body includes an items[].keys field that was not being parsed or returned in PrefopRet.Items.Keys.

Changes

  1. media/apis/prefop/api.go:

    • Added Keys []string field to PfopTaskItem struct
    • Added corresponding JSON tag "keys,omitempty" to jsonPfopTaskItem struct
    • Updated MarshalJSON() method to include Keys field
    • Updated UnmarshalJSON() method to populate Keys field from JSON response
  2. storage/pfop.go:

    • Updated Prefop() method to copy Keys field from API response to the returned FopResult

Testing

The fix ensures that when the Qiniu API returns multiple file keys in the prefop response, they are now properly captured in the PrefopRet.Items[].Keys field.

Fixes #177

When a prefop operation (e.g., vsample) generates multiple files,
the HTTP response body includes an items[].keys field that was not
being parsed or returned in PrefopRet.Items.Keys.

This commit fixes the issue by:
1. Adding Keys field to PfopTaskItem struct in media/apis/prefop/api.go
2. Adding corresponding JSON marshaling/unmarshaling support
3. Updating storage/pfop.go Prefop() method to copy Keys from API response

Fixes #177

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: nighca <[email protected]>
@qiniu-prow
Copy link

qiniu-prow bot commented Dec 17, 2025

Hi @xgopilot[bot]. Thanks for your PR.

I'm waiting for a qiniu member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@xgopilot
Copy link
Contributor Author

xgopilot bot commented Dec 17, 2025

Code Review Complete

I've reviewed the changes in PR #178 that add support for the keys field in prefop result items. The implementation correctly adds the missing field across the API and storage layers.

Review Summary

Files Changed:

  • media/apis/prefop/api.go: Added Keys []string field to PfopTaskItem struct with proper JSON marshaling/unmarshaling
  • storage/pfop.go: Updated Prefop() to copy the Keys field from API response

Issues Found

1. Validation Logic Inconsistency (media/apis/prefop/api.go:76-96)

The validate() method treats several fields as required that should be optional:

func (j *PfopTaskItem) validate() error {
    if j.Command == "" {
        return errors.MissingRequiredFieldError{Name: "Command"}
    }
    if j.Code == 0 {
        return errors.MissingRequiredFieldError{Name: "Code"}
    }
    if j.Description == "" {
        return errors.MissingRequiredFieldError{Name: "Description"}
    }
    if j.Hash == "" {
        return errors.MissingRequiredFieldError{Name: "Hash"}
    }
    if j.ObjectName == "" {
        return errors.MissingRequiredFieldError{Name: "ObjectName"}
    }
    if j.ReturnOld == 0 {
        return errors.MissingRequiredFieldError{Name: "ReturnOld"}
    }
    return nil
}

Problem: The validation enforces that Hash, ObjectName, and ReturnOld must be non-empty/non-zero, but these are optional fields (they have omitempty in JSON tags or are not always present). Specifically:

  • When a task fails, Hash and ObjectName may be empty (only Error is populated)
  • The validation checks ReturnOld == 0 but zero is a valid value (it's an int64 that could legitimately be 0)
  • The validation is called during MarshalJSON(), which means serializing a failed task would fail validation

Note: This issue exists in the current codebase and is not introduced by this PR. However, it may affect the usability of the new Keys field when tasks fail.

2. Missing Keys Field Validation

While the new Keys field is properly added, there's no validation logic to ensure consistency. Consider adding a check to warn if both ObjectName and Keys are populated (unclear from API documentation if this is valid).

Verification Needed

  1. Test Coverage: No test files were modified. Tests should be added to verify:

    • Keys field is correctly populated when API returns multiple keys
    • Keys field is correctly marshaled/unmarshaled
    • Backward compatibility when Keys is absent from API response
  2. API Documentation: Confirm the exact behavior when both ObjectName (single key) and Keys (multiple keys) are present in the API response. Is this mutually exclusive or can both be set?

Positive Aspects

  • The implementation is consistent across both the API layer and storage layer
  • Proper use of omitempty JSON tag for the optional field
  • The change is backward compatible (existing code without Keys will continue to work)
  • The String() method in storage/pfop.go:87-136 already handles the Keys field display

👉 Want me to re-run this review? Just type /review in the comments! For more usage examples, visit CodeAgent GitHub Repository.

@nighca
Copy link

nighca commented Dec 17, 2025

@YangSen-qn 帮 review 下这个 PR?

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.

keys in prefop result items is not correctly returned

3 participants