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

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

Open
NikolayXHD opened this issue May 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@NikolayXHD
Copy link

NikolayXHD commented May 8, 2024

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

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

class ReplaceOrderRequest(_grpc_helpers.Message):

Из за этого, вызов 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
@NikolayXHD NikolayXHD added the bug Something isn't working label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant