Skip to content

base

NullableBaseModel

Bases: BaseModel

Base model that allows fields to be None. This is useful for cases where fields may not always have a value.

null classmethod

null(quiet: bool = True) -> Self

Returns a null instance of the model with all fields set to None. This is useful for cases where no data is expected.

Parameters:

Name Type Description Default
quiet bool

If True, suppresses logging of the null response (default: True)

True

Returns:

Type Description
Self

A null instance of the model with all fields set to None.

Source code in src/nexosapi/domain/base.py
@classmethod
def null(cls: type[typing.Self], quiet: bool = True) -> typing.Self:
    """
    Returns a null instance of the model with all fields set to None.
    This is useful for cases where no data is expected.

    :param quiet: If True, suppresses logging of the null response (default: True)
    :return: A null instance of the model with all fields set to None.
    """
    nulled_data = cls._inspect_fields()
    non_empty_fields_data = {k: v for k, v in nulled_data.items() if v is not None}
    if not quiet:
        logging.warning(f"[SDK] Returning null response: {non_empty_fields_data}")
    return cls.model_validate(non_empty_fields_data)

model_dump

model_dump(
    *,
    mode: Literal["json", "python"] = "python",
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    context: Any | None = None,
    by_alias: bool | None = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    round_trip: bool = False,
    warnings: bool
    | Literal["none", "warn", "error"] = True,
    fallback: Callable[[Any], Any] | None = None,
    serialize_as_any: bool = False,
) -> dict[str, Any]

Dumps the model to a dictionary, excluding fields that are None.

Parameters:

Name Type Description Default
mode Literal['json', 'python']

The mode to use for dumping the model (json or python).

'python'
include IncEx | None

Fields to include in the output.

None
exclude IncEx | None

Fields to exclude from the output.

None
context Any | None

Contextual information to include in the output.

None
by_alias bool | None

Whether to use field aliases in the output.

None
exclude_unset bool

Whether to exclude unset fields from the output.

False
exclude_defaults bool

Whether to exclude fields with default values from the output.

False
exclude_none bool

Whether to exclude fields with None values from the output.

False
round_trip bool

Whether to enable round-trip serialization.

False
warnings bool | Literal['none', 'warn', 'error']

Warning level for the serialization process.

True
fallback Callable[[Any], Any] | None

Fallback function to call in case of serialization errors.

None
serialize_as_any bool

Whether to serialize the model as "any" type.

False

Returns:

Type Description
dict[str, Any]

A dictionary representation of the model.

Source code in src/nexosapi/domain/base.py
def model_dump(  # noqa: PLR0913
    self,
    *,
    mode: Literal["json", "python"] = "python",  # type: ignore
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    context: Any | None = None,
    by_alias: bool | None = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,  # noqa: ARG002
    round_trip: bool = False,
    warnings: bool | Literal["none", "warn", "error"] = True,
    fallback: Callable[[Any], Any] | None = None,
    serialize_as_any: bool = False,
) -> dict[str, Any]:
    """
    Dumps the model to a dictionary, excluding fields that are None.

    :param mode: The mode to use for dumping the model (json or python).
    :param include: Fields to include in the output.
    :param exclude: Fields to exclude from the output.
    :param context: Contextual information to include in the output.
    :param by_alias: Whether to use field aliases in the output.
    :param exclude_unset: Whether to exclude unset fields from the output.
    :param exclude_defaults: Whether to exclude fields with default values from the output.
    :param exclude_none: Whether to exclude fields with None values from the output.
    :param round_trip: Whether to enable round-trip serialization.
    :param warnings: Warning level for the serialization process.
    :param fallback: Fallback function to call in case of serialization errors.
    :param serialize_as_any: Whether to serialize the model as "any" type.

    :return: A dictionary representation of the model.
    """
    return super().model_dump(
        mode=mode,
        include=include,
        exclude=exclude,
        context=context,
        by_alias=by_alias,
        exclude_unset=exclude_unset,
        exclude_defaults=exclude_defaults,
        exclude_none=True,
        round_trip=round_trip,
        warnings=warnings,
        fallback=fallback,
        serialize_as_any=serialize_as_any,
    )