Skip to content

fix(auth): improving cache handling and error handling#52

Merged
rogerrafaeldefranca merged 2 commits into
mainfrom
fix/auth-cache
May 4, 2026
Merged

fix(auth): improving cache handling and error handling#52
rogerrafaeldefranca merged 2 commits into
mainfrom
fix/auth-cache

Conversation

@rogerrafaeldefranca

Copy link
Copy Markdown
Contributor

Contain

  • New feature
  • Bugfix
  • Tests
  • Documentation
  • Build/CI/CD
  • Breaking changes
  • Refactor

Details

  • Update: improving cache handling and error handling

@rogerrafaeldefranca rogerrafaeldefranca self-assigned this May 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces graceful handling of cache failures in the remote authorization logic by wrapping cache operations in try...except blocks. It also includes a version bump to 0.4.3 and adds unit tests to verify system behavior when cache retrieval or storage fails. Feedback was provided to restore explicit checks for the existence of the cache object to avoid unnecessary AttributeError exceptions and misleading log warnings when no cache is configured.

Comment on lines +59 to +63
cached = None
try:
cached = await cache.get(key)
except Exception as cache_error:
logger.warning("Cache get failed, proceeding without cache: %s", cache_error)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The explicit check for the existence of the cache object was removed in this change. Since cache is optional and defaults to None, calling cache.get(key) will raise an AttributeError when no cache is configured. While the try...except block catches this, it results in misleading 'Cache get failed' warnings in the logs for a normal configuration. It is recommended to restore the if cache: check.

Suggested change
cached = None
try:
cached = await cache.get(key)
except Exception as cache_error:
logger.warning("Cache get failed, proceeding without cache: %s", cache_error)
cached = None
if cache:
try:
cached = await cache.get(key)
except Exception as cache_error:
logger.warning("Cache get failed, proceeding without cache: %s", cache_error)

Comment on lines +93 to +97
try:
value = json.dumps({"authorized": authorized, "context": context})
await cache.set(key, value, cache_ttl)
except Exception as cache_error:
logger.warning("Cache set failed, proceeding without cache: %s", cache_error)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the cache retrieval, the check if cache: was removed here. If cache is None, calling cache.set(...) will raise an AttributeError. This should be avoided by checking for the cache object's existence explicitly to prevent unnecessary exceptions and misleading log messages.

Suggested change
try:
value = json.dumps({"authorized": authorized, "context": context})
await cache.set(key, value, cache_ttl)
except Exception as cache_error:
logger.warning("Cache set failed, proceeding without cache: %s", cache_error)
if cache:
try:
value = json.dumps({"authorized": authorized, "context": context})
await cache.set(key, value, cache_ttl)
except Exception as cache_error:
logger.warning("Cache set failed, proceeding without cache: %s", cache_error)

@rogerrafaeldefranca rogerrafaeldefranca merged commit 92dae41 into main May 4, 2026
0 of 5 checks passed
@rogerrafaeldefranca rogerrafaeldefranca deleted the fix/auth-cache branch May 4, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants