def _update_with_additional_data()

in modular_sdk/models/pynamodb_extension/base_safe_update_model.py [0:0]


    def _update_with_additional_data(cls, document: dict,
                                     additional_data: dict):
        """
        Kind of deep update
        :param document:
        :param additional_data:
        :return:
        """
        for key, value in additional_data.items():
            if key not in document:  # not defined
                document[key] = value
                continue
            # deep update
            doc = document[key]
            if type(doc) != type(value):
                _LOG.warning(
                    'Somehow the type of existing model declaration '
                    f'does not correspond to the type of additional '
                    f'value: {doc} - {value}'
                )
                continue
            if isinstance(doc, dict):
                cls._update_with_additional_data(doc, value)
            elif isinstance(doc, list):  # list of dicts
                # here there is a problem. We keep nested additional
                # data for lists by its order. But nothing prevents us from
                # changing the number of items in the list or clearing it,
                # for example. Currently, it will work correctly in case the
                # items of the list are not impaired
                for i, dct in enumerate(doc):
                    _data = value[i] if len(value) > i else None
                    if _data:
                        cls._update_with_additional_data(dct, _data)