0

while reading from remote file, which gives me data in form of dict with key. Then am trying to create record by looping.

Also, the table has _sql_contrain. So whenever the bad query happens, I want to skip the line instead aborting entire transaction(which happens now with my code). Any idea how ?

    def update_fn(self, sale, data):
    try:
        # Remove existing
        for existing_rec in sale.prop_ids:
            sale.prop_ids = [(2, existing_rec.id)]

        for prop in data["****"]:
            try:
                vals = {
                    "number": prop[0],
                    "name": prop[1],
                    "selection": prop[2],
                    "value": prop[3],
                }
                sale.prop_ids = [(0, 0, vals)]
            except IndexError:
                _logger.error(
                    "Insufficient Data: skipping line",
                )
            except IntegrityError:
                _logger.error(
                    "Unique Constrain Error"
                )
                return False

    except KeyError:
        _logger.error(
            "Data not found: skipping file"
        )
        return False
    except Exception as e:
        _logger.error("Error - %s", e)
        return False
NinjaBat
  • 370
  • 4
  • 20

0 Answers0