Skip to content

EmployeesEmployee.to_dict() crashes when bank_number_format is null #40

Description

@Neeklass

Description

EmployeesEmployee.to_dict() raises an AttributeError when the API returns
null for bank_number_format.

The generated from_dict() method explicitly converts JSON null to Python
None:

bank_number_format = (
    EmployeesEmployeeBankNumberFormat(_bank_number_format)
    if _bank_number_format is not None
    else None
)

However, to_dict() assumes every non-Unset value is an enum:

if not isinstance(self.bank_number_format, Unset):
    bank_number_format = self.bank_number_format.value

Because None is not an Unset, this attempts to access None.value.

Environment

  • factorial-api-client==2.0.2
  • Python 3.14
  • Factorial API version 2026-07-01

Minimal reproduction

from factorial_api_client.generated.models.employees_employee import (
    EmployeesEmployee,
)

employee = EmployeesEmployee(
    id="12345",
    access_id="3543",
    first_name="John",
    last_name="Doe",
    full_name="John Doe",
    company_id="999",
    location_id="888",
    created_at="2026-08-05T00:00:00Z",
    updated_at="2026-08-05T00:00:00Z",
    is_terminating=False,
    attendable=True,
    bank_number_format=None,
)

employee.to_dict()

Actual result

AttributeError: 'NoneType' object has no attribute 'value'

Expected result

employee.to_dict()["bank_number_format"] is None

The model should serialize a nullable bank_number_format without raising an
exception.

Suggested fix

Handle None separately in the generated serializer:

bank_number_format: str | None | Unset = UNSET

if self.bank_number_format is None:
    bank_number_format = None
elif not isinstance(self.bank_number_format, Unset):
    bank_number_format = self.bank_number_format.value

The generated type annotation should also include None:

bank_number_format: EmployeesEmployeeBankNumberFormat | None | Unset = UNSET

A round-trip regression test would cover the issue:

payload = {
    # required employee fields...
    "bank_number_format": None,
}

employee = EmployeesEmployee.from_dict(payload)

assert employee.to_dict()["bank_number_format"] is None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions