Skip to content

coroutine '<method that is cached>' was never awaited #59

Description

@Pegietix

Hey,
I am using your library and everything works fine for "normal" requests.

Problem arises, when I want to call cached method from within the same service.

My route:

@router.get('/get-fiat-currency-choices')
@cache()
def get_fiat_currency_choices():
    response_data = requests.get(f'{CURRENCY_EXCHANGE_API_URL}/currencies').json()

    choices = []
    for symbol, name in response_data.items():
        choices.append(
            {
                'symbol': symbol,
                'name': name,
            }
        )

    return choices

I am trying to call it with:

    @validator('currency')
    def validate_currency(cls, val):
        allowed_currencies = [currency['symbol'] for currency in get_fiat_currency_choices()]
        if val not in allowed_currencies:
            raise ValidationError('Currency is not supported.')
        return val

Error I am getting:

RuntimeWarning: coroutine 'get_fiat_currency_choices' was never awaited
2021-08-14T17:24:37.540579531Z   allowed_currencies = [currency['symbol'] for currency in get_fiat_currency_choices()]
2021-08-14T17:24:37.540585575Z RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Would appreciate any help, thanks!

P.S. The same thing occurs when I am using similar library 'fastapi-cache2' (https://github.com/long2ice/fastapi-cache)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions