Skip to content

Preventing data mutation in format_fields #75

@mamico

Description

@mamico

def format_fields(self, fields):

The fields object passed as an argument is modified within the function, which can lead to issues if the function is called multiple times, as it may result in broken or unintended data.

For example, in the following snippet:

                if self.block["subblocks"][field_index].get("field_type") == "date":
                    field["value"] = api.portal.get_localized_time(field["value"])

It seems get_localized_time expects a datetime object or an ISO-formatted string, not a localized string.

A quick fix to avoid mutating the original fields object is to add a deepcopy at the start of the function:

def format_fields(self, fields):
    fields = deepcopy(fields)

@JeffersonBledsoe thoughts ?

see #34

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