def hydrate_runcaseversions(self, bundle):
        """
        Handle the runcaseversion creation during a POST of a new Run.

        Tastypie handles the creation of the run itself.  But we handle the
        RunCaseVersions and Results because we have special handler methods for
        setting the statuses which we want to keep DRY.

        """

        try:
            run = bundle.obj
            run.save()

            # walk results

            for data in bundle.data["runcaseversions"]:

                status = data.pop("status")

                # find caseversion for case
                cv = CaseVersion.objects.get(
                    productversion=run.productversion,
                    case=data.pop("case"),
                    )

                # create runcaseversion for this run to caseversion
                rcv, created = RunCaseVersion.objects.get_or_create(
                    run=run,
                    caseversion=cv,
                    )


                data["user"] = bundle.request.user
                data["environment"] = Environment.objects.get(
                    pk=data["environment"])

                # create result via methods on runcaseversion
                rcv.get_result_method(status)(**data)

            bundle.data["runcaseversions"] = []
            return bundle

        except __HOLE__ as e:
            raise ValidationError(
                "bad result object data missing key: {0}".format(e))

        except ObjectDoesNotExist as e:
            raise ValidationError(e)
dataset/ETHPy150Open mozilla/moztrap/moztrap/model/execution/api.py/RunResource.hydrate_runcaseversions