eprbell / dali-rp2

DaLI (Data Loader Interface) is a data loader and input generator for RP2 (https://pypi.org/project/rp2), the privacy-focused, free, open-source cryptocurrency tax calculator: DaLI removes the need to manually prepare RP2 input files. Just like RP2, DaLI is also free, open-source and it prioritizes user privacy.
https://pypi.org/project/dali-rp2/
Apache License 2.0
65 stars 42 forks source link

TypeError: RP2Decimal.__add__() got an unexpected keyword argument 'context' #242

Closed splix closed 3 months ago

splix commented 3 months ago

Running dali fails with:

ERROR: Fatal exception occurred:
Traceback (most recent call last):
  File "/dali-rp2/src/dali/dali_main.py", line 193, in _dali_main_internal
    resolved_transactions: List[AbstractTransaction] = resolve_transactions(transactions, dali_configuration, args.read_spot_price_from_web)
  File "/dali-rp2/src/dali/transaction_resolver.py", line 265, in resolve_transactions
    transaction = _update_spot_price_from_web(transaction, global_configuration)
  File "/dali-rp2/src/dali/transaction_resolver.py", line 138, in _update_spot_price_from_web
    if is_unknown(transaction.spot_price) or RP2Decimal(transaction.spot_price) == ZERO:  # type: ignore
  File "/dali-rp2/.venv/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 39, in __eq__
    return (self - other).quantize(CRYPTO_DECIMAL_MASK).__eq__(ZERO)
  File "/dali-rp2/.venv/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 68, in __sub__
    return RP2Decimal(Decimal.__sub__(self, other))
  File "/usr/local/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/_pydecimal.py", line 1257, in __sub__
    return self.__add__(other.copy_negate(), context=context)

Trying with dali from source at commit [97fcb78] (tag 0.6.10)

The installed version of rp2 is:

$ pip show rp2
Name: rp2
Version: 1.5.1
eprbell commented 3 months ago

Thanks for reporting. Is there any other information printed on the screen other than the stack trace? We would need to know what exact data is in the transaction that caused this. If there is no other info being printed, could you add a new log line just before line 138 of transaction resolver (before the if is_unknown(...):

LOGGER.info("resolving transaction: %s", str(transaction))

Then run again and check what is the last transaction being printed.

Feel free to remove any personally identifiable information from the transactions you post here.

splix commented 3 months ago

It can be reproduced with the following command:

python - << EOF
from rp2.rp2_decimal import RP2Decimal

RP2Decimal(1) < RP2Decimal(1)
EOF

Produces:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/rp2/src/rp2/rp2_decimal.py", line 58, in __lt__
    return not self.__ge__(other)
  File "/rp2/src/rp2/rp2_decimal.py", line 47, in __ge__
    return (self - other).quantize(CRYPTO_DECIMAL_MASK).__ge__(ZERO)
  File "/rp2/src/rp2/rp2_decimal.py", line 68, in __sub__
    return RP2Decimal(Decimal.__sub__(self, other))
  File "/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_pydecimal.py", line 1257, in __sub__
    return self.__add__(other.copy_negate(), context=context)
TypeError: __add__() got an unexpected keyword argument 'context'

NOTE: I downgraded Python to 3.9 thinking it may be something with 3.10 which is in the original error. And tried with rp2 sources as well. Same result.

eprbell commented 3 months ago

The command you pasted works for me: the error you got seems similar to what was observed in this RP2 issue.

splix commented 3 months ago

That seems to be the reason.

My system Python installation was also using _pydecimal.py implementation. Switching to a python installed with brew (also ensuring I have brew install mpdecimal) fixed the issue.

Thank you