Skip to content

Commit

Permalink
Denote every field which is omitted when None.
Browse files Browse the repository at this point in the history
There are some fields that can be sent with `null` values over JSON, which
means they are set to `None` within Python. The broad config-based exclude
directive is not given any information about the field, only it's value, so
we can't use it to determine if a field should be excluded or not in the dict
that gets built.

Instead we create a helper function to build a field definition that has the
necessary exclude function. Any field that does not use this helper function
is permitted to be None/null. This is true of the MailboxGet.ids field in this
commit. A new test is added to maintain the behavior over time.
  • Loading branch information
EliRibble committed Jan 5, 2024
1 parent 9ea68cd commit 7c2a826
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions jmapc/models/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

from dataclasses_json import config

from ..serializer import Model
from ..serializer import Model, null_omitted_field
from .models import Operator, StrOrRef


@dataclass
class Mailbox(Model):
id: Optional[str] = field(metadata=config(field_name="id"), default=None)
name: Optional[str] = None
id: Optional[str] = null_omitted_field(metadata=config(field_name="id"))
name: Optional[str] = null_omitted_field()
sort_order: Optional[int] = 0
total_emails: Optional[int] = None
unread_emails: Optional[int] = None
total_threads: Optional[int] = None
unread_threads: Optional[int] = None
total_emails: Optional[int] = null_omitted_field()
unread_emails: Optional[int] = null_omitted_field()
total_threads: Optional[int] = null_omitted_field()
unread_threads: Optional[int] = null_omitted_field()
is_subscribed: Optional[bool] = False
role: Optional[str] = None
parent_id: Optional[str] = field(
metadata=config(field_name="parentId"), default=None
role: Optional[str] = null_omitted_field()
parent_id: Optional[str] = null_omitted_field(
metadata=config(field_name="parentId"),
)


@dataclass
class MailboxQueryFilterCondition(Model):
name: Optional[StrOrRef] = None
role: Optional[StrOrRef] = None
parent_id: Optional[StrOrRef] = None
has_any_role: Optional[bool] = None
is_subscribed: Optional[bool] = None
name: Optional[StrOrRef] = null_omitted_field()
role: Optional[StrOrRef] = null_omitted_field()
parent_id: Optional[StrOrRef] = null_omitted_field()
has_any_role: Optional[bool] = null_omitted_field()
is_subscribed: Optional[bool] = null_omitted_field()


@dataclass
Expand Down

0 comments on commit 7c2a826

Please sign in to comment.