Skip to content

last_date_to_pay field can be none #159

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

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions iec_api/models/electric_bill.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Electric Bills."""

from dataclasses import dataclass, field
from typing import Optional

from mashumaro import DataClassDictMixin, field_options
from mashumaro.codecs import BasicDecoder
Expand Down Expand Up @@ -47,8 +48,8 @@
class ElectricBill(DataClassDictMixin):
total_amount_to_pay: float = field(metadata=field_options(alias="totalAmountToPay"))
total_invoices_to_pay: int = field(metadata=field_options(alias="totalInvoicesToPay"))
last_date_to_pay: str = field(metadata=field_options(alias="lastDateToPay"))
invoices: list[Invoice]
last_date_to_pay: Optional[str] = field(metadata=field_options(alias="lastDateToPay"), default=None)


decoder = BasicDecoder(ResponseWithDescriptor[ElectricBill])
decoder = BasicDecoder(ResponseWithDescriptor[ElectricBill])
6 changes: 3 additions & 3 deletions iec_api/models/response_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ResponseDescriptor(DataClassDictMixin):
"""Response Descriptor"""

is_success: bool = field(metadata=field_options(alias="isSuccess"))
code: Optional[str]
description: Optional[str]
code: Optional[str] = None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason for setting default values, they'll be None by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some errors without this added line. for example: errorMessage": "Field \"response_descriptor\" of type ResponseDescriptor in ResponseWithDescriptor has invalid value {'isSuccess': True, 'code': '00'}",

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to parse the response:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 6, in __mashumaro_from_dict__
mashumaro.exceptions.MissingField: Field "data" of type Optional[Any] is missing in ResponseWithDescriptor instance

This means that data field (and not code) can be None.
Which you already added.

description: Optional[str] = None


@dataclass
Expand All @@ -34,5 +34,5 @@ class ErrorResponseDescriptor(DataClassDictMixin):
class ResponseWithDescriptor(Generic[T], DataClassDictMixin):
"""Response With Descriptor"""

data: Optional[T]
response_descriptor: ResponseDescriptor = field(metadata=field_options(alias=RESPONSE_DESCRIPTOR_FIELD))
data: Optional[T] = None
Loading