RussianInvestments / invest-python

Invest Python gRPC client
https://russianinvestments.github.io/invest-python/
Apache License 2.0
68 stars 21 forks source link

[Bug] Пропущен декоратор @dataclass в классе ReplaceOrderRequest #27

Open NikolayXHD opened 6 months ago

NikolayXHD commented 6 months ago

Что случилось?

Пропущен декоратор @dataclass в классе ReplaceOrderRequest

https://github.com/RussianInvestments/invest-python/blob/5836ddce21d8dbbe48a5325f45f0167f4d62db03/tinkoff/invest/schemas.py#L2213

Из за этого, вызов client.orders.replace_order(request) падает с исключением

AttributeError: 'Field' object has no attribute 'value'

Если добавить @dataclass в исходниках в schemas.py, исключения нет, вызов API срабатывает штатно.

Воспроизведение

import uuid

from tinkoff.invest import ReplaceOrderRequest, Quotation
from tinkoff.invest.sandbox.client import SandboxClient

TOKEN=''

def main() -> None:
    with SandboxClient(token=TOKEN) as client:
        request = ReplaceOrderRequest()
        request.account_id = '2048246272'
        request.order_id = str(uuid.uuid4())
        request.idempotency_key = '123'
        request.price = Quotation(
            units=11, nano=0
        )
        request.quantity = 11
        order_id = client.orders.replace_order(
            request
        )
        print(order_id)

if __name__ == '__main__':
    main()

Workaround

Заполнить необязательное поле

request.price_type = PriceType.PRICE_TYPE_UNSPECIFIED

Tinkoff Invest Version

0.2.0-beta98

Python Version

3.12

OS

MacOS

Логи

/Users/nmidalgodias/Library/Caches/pypoetry/virtualenvs/sandbox-WXRoqCNu-py3.12/bin/python /Users/nmidalgodias/git/sandbox/src/make_targets/experimental/tinkoff_repro.py 
Traceback (most recent call last):
  File "/Users/nmidalgodias/git/sandbox/src/make_targets/experimental/tinkoff_repro.py", line 27, in <module>
    main()
  File "/Users/nmidalgodias/git/sandbox/src/make_targets/experimental/tinkoff_repro.py", line 20, in main
    order_id = client.orders.replace_order(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nmidalgodias/Library/Caches/pypoetry/virtualenvs/sandbox-WXRoqCNu-py3.12/lib/python3.12/site-packages/tinkoff/invest/_errors.py", line 23, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nmidalgodias/Library/Caches/pypoetry/virtualenvs/sandbox-WXRoqCNu-py3.12/lib/python3.12/site-packages/tinkoff/invest/services.py", line 1401, in replace_order
    request=_grpc_helpers.dataclass_to_protobuff(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nmidalgodias/Library/Caches/pypoetry/virtualenvs/sandbox-WXRoqCNu-py3.12/lib/python3.12/site-packages/tinkoff/invest/_grpc_helpers.py", line 404, in dataclass_to_protobuff
    _update_field(first_arg, protobuff_obj, field_name, field_value)
  File "/Users/nmidalgodias/Library/Caches/pypoetry/virtualenvs/sandbox-WXRoqCNu-py3.12/lib/python3.12/site-packages/tinkoff/invest/_grpc_helpers.py", line 430, in _update_field
    setattr(protobuff_obj, field_name, field_value.value)
                                       ^^^^^^^^^^^^^^^^^
AttributeError: 'Field' object has no attribute 'value'

Process finished with exit code 1