feat: get plan bulk with cache#36
Conversation
| 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.
Bug: The get_plan_bulk method returns None for invalid tenants, which is then cached as a JSON "null". This causes validation errors on subsequent cache reads.
Severity: HIGH
Suggested Fix
Modify the get_plan_bulk method to not add entries for tenants with invalid plans to the results dictionary. Instead of results[tenant_id] = None, the code should simply continue or skip adding the key to the dictionary. This ensures the return value adheres to the dict[str, SubscriptionPlan] type hint and prevents None values from being cached.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: api/services/billing_service.py#L292
Potential issue: In the `get_plan_bulk` method, when subscription plan data validation
fails for a given tenant, the code assigns `None` to the results for that tenant ID.
This `None` value is then passed to `get_plan_bulk_with_cache`, which attempts to cache
it. The caching logic serializes `None` into the JSON string `"null"` and stores it in
Redis. On subsequent cache reads for that tenant, the `"null"` string is deserialized
back to a `None` object, which then causes a validation failure when
`subscription_adapter.validate_python` is called, as `None` is not a valid
`SubscriptionPlan` object. This leads to repeated cache misses and unnecessary API calls
for invalid tenants.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Benchmark PR from qodo-benchmark#445