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

using retry_on_exception with class function is not working #2

Open
TarikIbrahim opened this issue Jan 23, 2023 · 2 comments
Open

using retry_on_exception with class function is not working #2

TarikIbrahim opened this issue Jan 23, 2023 · 2 comments

Comments

@TarikIbrahim
Copy link

Hello,
trying the following code is not working

def catch_general_exception(self,ex):
       return isinstance(ex,Exception)

@retry(retry_on_exception=catch_general_exception)
def do_some_code:
       # do some code
       try:
              # some ode
       except Exception as ex:

passing catch_general_exception is not accepted even i passed self.catch_general_exception

@PamelaM
Copy link

PamelaM commented Aug 28, 2024

I suspect that you meant something like this:

class SomeClass:
    def catch_general_exception(self, ex):
        return isinstance(ex,Exception)

    @retry(retry_on_exception=self.catch_general_exception)
    def do_some_code(self):
        # do some code
        try:
            # some ode
        except Exception as ex:
            raise

This won't work because self isn't defined when the @retry decorator is being created.

This should work, though:

def catch_general_exception(ex):
    return isinstance(ex,Exception)

class SomeClass:

    @retry(retry_on_exception=catch_general_exception)
    def do_some_code(self):
        # do some code
        try:
            # some ode
        except Exception as ex:
            raise

This might even work: @retry(retry_on_exception=lamba ex: isinstance(ex, Exception)

@PamelaM
Copy link

PamelaM commented Aug 28, 2024

Actually, after doing more reading, your use case is already supported:

@retry(
    retry_on_exception=(Exception,)
)

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

No branches or pull requests

2 participants