コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
9446 ビュー

Hello,


I have 1 custom class which have minimum 30000 record which have images are stored.

Now, I want to resize all the images which is stored and also creating new record with image.


First image field is like as below

variants_image_medium = fields.Binary('Product Image', store=True, attachment=True)


Now, I converted image field as shown below

variants_image_medium = fields.Binary('Product Image', inverse='_compute_images', store=True, attachment=True, readonly=False)


@api.multi
def _compute_images(self):
        for rec in self:
            if rec.variants_image_medium:
                image = tools.image_resize_image_small(rec.variants_image_medium)
                rec.variants_image_medium = image
                return rec


 It gives me error,

RuntimeError: maximum recursion depth exceeded


How to Solve that error ?

Thanks in Advance,


アバター
破棄
最善の回答

For a computed function returning arguments should keep the format

{'value':
     { 'field_name':field_value}
}

So please check the  rec satisfies this.



アバター
破棄
最善の回答

In your inverse you are changing current field, what invokes this inverse recursively:

Field value x > Field value x1 > Field value x2 > .... > 


You should

1) either store resized image in a separated field

2) or add a condition in inverse not to make recursion, e.g.:

already_resized = fields.Boolean()

@api.multi
def _compute_images(self):
        for rec in self:
            if not 
already_resized and rec.variants_image_medium:

                image = tools.image_resize_image_small(rec.variants_image_medium)
                rec.variants_image_medium = image
                rec.
already_resized = True

アバター
破棄
関連投稿 返信 ビュー 活動
1
11月 24
39625
1
8月 16
5692
3
8月 24
13628
2
2月 24
3364
2
4月 23
3273