alpacahq / alpacahq/alpaca-py

[Bug]: UploadW8BenDocumentRequest fails due type errors

Aperta
#226 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
1.5k
Fork
398
Merge medio
1g 16h
PR unite (30g)
6

Descrizione

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

When trying to upload a `W8BenDocument `using `UploadW8BenDocumentRequest` two typing errors are rised.

The first one is because of type date not converted to string, the other is because of the type IPAddress not converted to string.

### Expected Behavior

Date and IPAddress should be converted to string to make them json serializable

### SDK Version I encountered this issue in

alpaca-py master

### Steps To Reproduce
Currently date and IPAddress attributes are not converted to string. W8BenDocument has 2 `date` attributes: date and date_of_birth. Which causes this error:

`requests.exceptions.InvalidJSONError: Object of type date is not JSON serializable`

Fixing the issue described above, an other error is rised:

`requests.exceptions.InvalidJSONError: Object of type IPv4Address is not JSON serializable`

This other error is again because of the type IPAddress not converted to string.

You can reproduce the error on main branch using a broker_client and this request:

```
from datetime import datetime, date
from alpaca.broker.requests import UploadW8BenDocumentRequest
from alpaca.broker.models.documents import W8BenDocument, IPv4Address

account_id = "2a87c088-ffb6-472b-a4a3-cd9305c8605c"
document_date = date(2023, 1, 3)
date_of_birth = date(1999, 1,23)
timestamp = datetime.now()
ip_address=IPv4Address(address="189.147.173.150")

broker_client.upload_documents_to_account(
account_id=account_id,
document_data=[
UploadW8BenDocumentRequest(
content_data=W8BenDocument(
country_citizen="Other",
date=document_date,
date_of_birth=date_of_birth,
full_name="Some Name",
ip_address=ip_address,
permanent_address_city_state="Springfield",
permanent_address_country="US",
permanent_address_street="742 de Evergreen Terrace",
revision="10-2021",
signer_full_name="Some Name",
timestamp=timestamp,
foreign_tax_id="CXXC990123ME2",
),
)
],
)
```

### Filled out the Steps to Reproduce section?

- [X] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

### Anything else?

I've already fixed this, will push and create PR for feedback

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.