-
Notifications
You must be signed in to change notification settings - Fork 0
feat: get plan bulk with cache #23
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
base: devin_pr_code_review_bench_100_devin2_base_feat_get_plan_bulk_with_cache_pr445
Are you sure you want to change the base?
Conversation
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.
| logger.exception( | ||
| "get_plan_bulk: failed to validate subscription plan for tenant(%s)", tenant_id | ||
| ) | ||
| results[tenant_id] = None |
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.
🔴 get_plan_bulk stores None for invalid tenants instead of skipping them
When validation fails for a tenant's subscription plan in get_plan_bulk, the code incorrectly stores None in the results dictionary instead of skipping the invalid entry.
Click to expand
Issue Details
At line 292, when validation fails:
results[tenant_id] = NoneThis contradicts:
- The return type annotation
dict[str, SubscriptionPlan]which doesn't includeNone - The test
test_get_plan_bulk_with_invalid_tenant_plan_skippedwhich expectsassert "tenant-invalid" not in result
Impact
- Callers expecting
SubscriptionPlanvalues will receiveNoneunexpectedly - The downstream
get_plan_bulk_with_cachefunction will cacheNonevalues (serialized as"null") to Redis, causing validation failures on subsequent cache reads - Type safety is violated as the return type doesn't match the actual returned values
Expected Behavior
Invalid tenant plans should be skipped entirely (not added to results), matching the test expectation and type annotation.
Recommendation: Remove line 292 (results[tenant_id] = None) so that invalid tenant plans are simply not added to the results dictionary, matching the expected behavior from the test.
Was this helpful? React with 👍 or 👎 to provide feedback.
| for tenant_id, subscription_plan in bulk_plans.items(): | ||
| tenant_plans[tenant_id] = subscription_plan | ||
| plans_to_cache[tenant_id] = subscription_plan |
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.
🔴 get_plan_bulk_with_cache caches None values from get_plan_bulk, causing cache pollution
When get_plan_bulk returns None values for invalid tenants (due to BUG-0001), get_plan_bulk_with_cache caches these None values to Redis, which will fail validation when retrieved later.
Click to expand
Issue Details
At lines 365-367:
for tenant_id, subscription_plan in bulk_plans.items():
tenant_plans[tenant_id] = subscription_plan # subscription_plan can be None
plans_to_cache[tenant_id] = subscription_planAnd at lines 373-377:
for tenant_id, subscription_plan in bulk_plans.items():
redis_key = cls._make_plan_cache_key(tenant_id)
json_str = json.dumps(subscription_plan) # json.dumps(None) = "null"
pipe.setex(redis_key, cls._PLAN_CACHE_TTL, json_str)Impact
Nonevalues are stored intenant_plansand returned to callersjson.dumps(None)produces"null", which gets cached in Redis- When this cached
"null"is later retrieved and parsed,subscription_adapter.validate_python(plan_dict)will fail becauseNonedoesn't matchSubscriptionPlanschema - This causes the tenant to be treated as a cache miss on every subsequent call, defeating the purpose of caching
Expected Behavior
Only valid SubscriptionPlan values should be cached. None values should be filtered out before caching.
Recommendation: Add a check to filter out None values before storing in tenant_plans and plans_to_cache. For example:
for tenant_id, subscription_plan in bulk_plans.items():
if subscription_plan is not None:
tenant_plans[tenant_id] = subscription_plan
plans_to_cache[tenant_id] = subscription_planWas this helpful? React with 👍 or 👎 to provide feedback.
Benchmark PR from qodo-benchmark#445