Skip to content
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

AttributeError in storage/redis_cluster.py due to undefined self.dependency #238

Open
YiJun10565 opened this issue Oct 24, 2024 · 0 comments
Labels

Comments

@YiJun10565
Copy link

I encountered an issue where the redis_cluster.py module doesn't define self.dependency. This leads to an AttributeError when the parent property self.base_exceptions attempts to call self.dependency.

Expected Behaviour

The code should execute without errors, assuming self.dependency is properly defined.

Current Behaviour

The following error occurs:

AttributeError: 'RedisClusterStorage' object has no attribute 'dependency'

Steps to Reproduce

Use the redis_cluster.py module with a Redis cluster.

Call functions that invoke the self.base_exceptions property, such as through the following chain of functions:
The error will occur when the try block in base.py raises an exception.

# file: limits/redis.py
@property
    def base_exceptions(
        self,
    ) -> Union[Type[Exception], Tuple[Type[Exception], ...]]:  # pragma: no cover
        return self.dependency.RedisError  # type: ignore[no-any-return]

# file: limits/storage/base.py
def _wrap_errors(storage: Storage, fn: Callable[P, R]) -> Callable[P, R]:
    @functools.wraps(fn)
    def inner(*args: P.args, **kwargs: P.kwargs) -> R:
        try:
            return fn(*args, **kwargs)
        except storage.base_exceptions as exc:
            if storage.wrap_exceptions:
                raise errors.StorageError(exc) from exc
            raise
    return inner

# file: limits/strategies.py
def test(self, item: RateLimitItem, *identifiers: str, cost: int = 1) -> bool:

    return (
        cast(MovingWindowSupport, self.storage).get_moving_window(
            item.key_for(*identifiers),
            item.amount,
            item.get_expiry(),
        )[1]
        <= item.amount - cost
    )

Your Environment

  • limits version: 3.13.0
  • python version: 3.11.7
@YiJun10565 YiJun10565 added the bug label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant