Exemplo n.º 1
0
    def parse_data_to_items(
        self,
        data=None,
        **kwargs,
    ) -> Iterator[dict]:

        if not isinstance(data, DataBag):
            if data:
                kwargs["main"] = data

            data = DataBag(**kwargs)

        if not data.has_model_manger_instance():
            data.init_model_manager(self)

        drop_item_exceptions = []

        for iter_data in self._apply_data_processors(data):
            try:
                yield self._data_to_item(iter_data)
            except self._drop_item_exception as drop_item_exception:
                # we store drop item exceptions so that other variations could
                # get processed and we throw stored exceptions after iteration
                # has ended
                drop_item_exceptions.append(drop_item_exception)

        if drop_item_exceptions:
            if len(drop_item_exceptions) > 1:
                raise self._drop_item_exception(drop_item_exceptions)

            raise drop_item_exceptions[0]
Exemplo n.º 2
0
def load_data_bag_with_model():
    model_manager = ModelManager(ProductJsonModel())

    data_bag = DataBag(main=json.dumps(data_dict.item_with_options))
    data_bag.init_model_manager(model_manager)
    return data_bag