You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_9 (already cloned)
- Base commit: c5c0e677f2a2d43170a66330c98e0ebc4d771717
- Task ID: juspay__hyperswitch-8389
- Version: v1.114.0
TASK DESCRIPTION: Bug: [FEATURE] Kv Redis feature for V2 models
Feature Description
Extend kv support for v2 models
Possible Implementation
Use existing construct to extend to v2 models
Have you spent some time checking if this feature request has been raised before?
- I checked and didn't find a similar issue
Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to submit a PR?
Yes, I am willing to submit a PR!
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
#8389
- Added Kv Redis support to - payment_intent V2, payment_attempt V2 models
- Added enable Kv route for v2 merchant-account
added enable kv api for v2 merchant account
curl --location 'https://<host>/v2/merchant-accounts/:mid/kv' \ --header 'Authorization: admin-api-key=***' \ --header 'x-organization-id:***' \ --header 'Content-Type: application/json' \ --data '{"kv_enabled" : true}'Additional Changes
- This PR modifies the API contract
Assistant
I'll help you implement KV Redis support for V2 models in the hyperswitch repository. Let me start by exploring the codebase to understand the current implementation and identify what needs to be extended.
First, I'll create a plan of action for implementing this feature.
Assistant
Let me start by exploring the existing KV Redis implementation to understand how it's currently structured for V1 models.
Assistant
Now let me look for V2 model files to understand their structure:
Assistant
Let me search more broadly for V2 models:
Assistant
Let me search more specifically for V2-related files and directories:
Assistant
Let me search for API v2 directories and files:
Assistant
Let me search for merchant accounts in the codebase to understand the structure better:
Assistant
Let me examine the existing KV implementation to understand how it works:
Assistant
(no content)
Assistant
Let me check the storage implementation for KV redis:
Assistant
Now let me search for the API routes to understand how merchant accounts are handled:
Assistant
Let me check the API structure:
Assistant
Let me check for merchant account V2 API files specifically:
Assistant
Let me examine the main router to understand how the routes are organized:
Assistant
Let me check for routes that might handle merchant accounts:
Assistant
Let me look for the merchant account routes specifically:
Assistant
Let me check the main routes file and openapi specifications to better understand how the API structure works:
Assistant
Let me search for the specific endpoint mentioned in the task - the merchant account KV enable endpoint:
Assistant
Let me look at the admin routes and models to understand the current implementation:
Assistant
Now I can see that there's already a merchant account KV toggle functionality in the admin routes (lines 915-939). Let me check the API models to understand what's expected:
Assistant
Let me search for the KV related structs in the admin models:
Assistant
Let me get a specific part of the admin model file that contains KV-related structures:
Assistant
Let me also check for any V2-specific models to understand how V2 models work. First, let me see the openapi specs to understand the API structure:
Assistant
Let me examine what models exist in the storage layer for payment_intent and payment_attempt:
Assistant
Let me examine the main payment intent and payment attempt models to understand how they are structured in the diesel models:
Assistant
Let me examine the current payment_intent model:
Assistant
Let me also check the payment_attempt model:
Assistant
Based on my exploration, I can see that the repository uses both V1 and V2 models, with KV Redis support already existing for V1 models. The task is to extend KV Redis support to V2 models specifically for
payment_intentandpayment_attempt.Looking at the current structure, I understand:
- KV Redis implementation already exists for V1 models in
diesel_models/src/kv.rs - There are V2 versions of
payment_intentandpayment_attemptindiesel_models/src/payment_intent.rsanddiesel_models/src/payment_attempt.rs - The
KVRouterStoresupports both V1 and V2 through feature flags - The task is to add KV Redis support for V2 models specifically
Let me start working on implementing the solution:
- KV Redis implementation already exists for V1 models in
Assistant
Now I need to add KV support for V2 models. Looking at the existing code in
diesel_models/src/kv.rs, I can see that it already handles V2 models with#[cfg(feature = "v2")]sections. However, I need to make sure thePaymentIntentUpdateMemsandPaymentAttemptUpdateMemsstructures in the KV module are properly configured for V2 models.Let me check the specific structure of the
PaymentIntentUpdateMemsandPaymentAttemptUpdateMemsin the KV module to see if they need updates for V2:Assistant
I can see that the KV structure already handles both V1 and V2 for
PaymentIntentUpdateMems. Now I need to check the implementation ofDBOperation::executemethod in the KV module to see if it handles V2 models correctly for payment_intent and payment_attempt.Looking at lines 114-135 of the kv.rs file, I can see that the
executemethod has#[cfg(feature = "v2")]blocks for handling payment attempt updates, but it seems to be missing for payment intent updates. Let me double-check that by looking closer at this area:Assistant
I can see that the KV implementation for V2 models already exists and looks correct for both payment_intent and payment_attempt. However, I need to make sure there are no issues or missing parts. Let me now check what happens when we use these V2 models in the KV system.
But first, let me understand the task requirements better by examining the existing V2 models more closely and also the KV functionality to see if there's anything missing.
Looking more carefully, I need to actually implement what's required. Since this is a bug report requesting extension of KV Redis support to V2 models, and it's stated that V2 models should support KV, but I don't see any explicit issues in the current code, let me double-check by creating an implementation that adds proper support.
Let me also check what
Updateable::PaymentIntentUpdateandUpdateable::PaymentAttemptUpdateenums contain:Assistant
Assistant
Let me now make a different approach. Since I'm confident that the KV infrastructure for V2 models already exists properly, I'll check if there are any missing imports or references needed for V2 models to work correctly in the KV system. Let me also check if there's any missing part in the Updateable enum.
Actually, let me approach this systematically by creating a proper implementation of the missing feature. Based on the task, the main issue appears to be that while KV support is extended to V2 models, there might be some specific configuration missing.
Looking at the issue more carefully, I believe the task is asking me to make sure KV Redis is working properly for V2 models, especially when the feature is enabled for V2.
But since I've verified that the code is already implemented properly, I think the issue might be that the KV Redis store needs to be made aware of V2 model keys. Let me take a look at how V2 merchant accounts are handled and make sure the KV system knows how to handle V2 keys.
Assistant
Let me examine the admin core module to see how KV toggling works:
Assistant
Let me examine that function to see how it works:
Assistant
After carefully reviewing the existing implementation, I believe the KV Redis support for V2 models is already properly implemented. Let me confirm this by checking if we're missing any specific part that might be related to V2 models.
Looking at the implementation details, it seems that:
- The KV Redis infrastructure (
diesel_models/src/kv.rs) already has proper V2 support with conditional compilation features - The storage scheme for merchant accounts already handles both V1 and V2 models
- The toggle KV functionality in admin core works for all merchant accounts
However, based on the task requirement to "extend kv support for v2 models" and "add enable kv api for v2 merchant-account", let me create a focused change to make sure V2 merchant accounts are properly supported in all aspects of KV handling.
But wait, upon closer inspection, I notice something crucial. The function in handles V2 models with a section for but there might be missing cases for V2 model partition keys.
- The KV Redis infrastructure (
Assistant
Based on my analysis, I can see that the backend functions exist but I need to make sure that V2-specific routes are properly defined for the KV operations. Let me check what the actual problem is.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.