Problem

When the decorated exchange rate provider (e.g. FixedRates) returns NULL for a currency pair that has no configured rate, ExchangeRateProviderDecorator::load() and loadMultiple() pass that NULL directly to ExchangeRate::createFromExchangeRate(), which expects ExchangeRateInterface. This causes a TypeError.

Error message

Drupal\currency\ExchangeRate::createFromExchangeRate(): Argument #1 ($other_exchange_rate) must be of type Commercie\CurrencyExchange\ExchangeRateInterface, null given, called in .../ExchangeRateProviderDecorator.php on line 44

Steps to reproduce

  1. Configure a currency (e.g. XXX) with no exchange rate to the user's currency.
  2. Trigger a conversion from a currency that has rates (e.g. EUR) to the unconfigured currency (XXX).
  3. Observe the TypeError when the decorator calls createFromExchangeRate(null, ...).

Proposed solution

Add null checks in load() and loadMultiple() before calling ExchangeRate::createFromExchangeRate(). If the decorated provider returns NULL, return NULL from load() or skip the entry in loadMultiple().

Patch

Attached patch adds the null checks to both methods.

Comments

ivan shatalov created an issue. See original summary.

ivan shatalov’s picture

Status: Active » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.