-
Notifications
You must be signed in to change notification settings - Fork 29.9k
[FIX] product: always compute zoomable with bin_size=False
#192047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Changing a product template's image with the `can_image_1024_be_zoomed` field present in the view produces a crash on save. **STEPS TO REPRODUCE** 1. Open a product form view 2. Using studio, add the `can_image_1024_be_zoomed` field 3. Change the image and save The product will be updated, but this error will be thrown: ``` binascii.Error: Incorrect padding ``` **CAUSE** https://github.com/odoo/odoo/blob/a74684777c27e26639b75b0668bb15afadb78c4f/addons/product/models/product_template.py#L186-L188 In the `RecordSet`'s context, `bin_size=True`, so accessing `image_<size>` returns a size instead of a binary. `_compute_can_image_1024_be_zoomed` calls `tools.is_image_size_above` with this binary size, while the method expects the full base64 encoded image. Ultimately, this causes `base64.b64decode` to crash with the above error. **FIX** Update the `RecordSet`'s context to `bin_size=False`. Accessing `image_<size>` from the `RecordSet` will then return the full binary instead of the size. **NOTES** In versions <17.0, read and write were done in separate network calls causing the recompute to happen during the flush of the write, which doesn't have `bin_size=True` in the context. Because the field is stored, the read will not cause a recompute and thus avoids any error. In >=17.0, because the read occurs before the flush, and the write has invalidated the field, the recompute will occur with the context of the read (`bin_size=True`), causing the issue. opw-4413647
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I advised the customer that they can remove it but they haven't responded. Ticket for more context: https://www.odoo.com/odoo/project/49/tasks/4413647 That being said, this error could be triggered any time this compute method is invoked with @robodoo r+ |
Changing a product template's image with the `can_image_1024_be_zoomed` field present in the view produces a crash on save. **STEPS TO REPRODUCE** 1. Open a product form view 2. Using studio, add the `can_image_1024_be_zoomed` field 3. Change the image and save The product will be updated, but this error will be thrown: ``` binascii.Error: Incorrect padding ``` **CAUSE** https://github.com/odoo/odoo/blob/a74684777c27e26639b75b0668bb15afadb78c4f/addons/product/models/product_template.py#L186-L188 In the `RecordSet`'s context, `bin_size=True`, so accessing `image_<size>` returns a size instead of a binary. `_compute_can_image_1024_be_zoomed` calls `tools.is_image_size_above` with this binary size, while the method expects the full base64 encoded image. Ultimately, this causes `base64.b64decode` to crash with the above error. **FIX** Update the `RecordSet`'s context to `bin_size=False`. Accessing `image_<size>` from the `RecordSet` will then return the full binary instead of the size. **NOTES** In versions <17.0, read and write were done in separate network calls causing the recompute to happen during the flush of the write, which doesn't have `bin_size=True` in the context. Because the field is stored, the read will not cause a recompute and thus avoids any error. In >=17.0, because the read occurs before the flush, and the write has invalidated the field, the recompute will occur with the context of the read (`bin_size=True`), causing the issue. opw-4413647 closes #192047 Signed-off-by: Samiul Hoque (saho) <saho@odoo.com>
Changing a product template's image with the `can_image_1024_be_zoomed` field present in the view produces a crash on save. **STEPS TO REPRODUCE** 1. Open a product form view 2. Using studio, add the `can_image_1024_be_zoomed` field 3. Change the image and save The product will be updated, but this error will be thrown: ``` binascii.Error: Incorrect padding ``` **CAUSE** https://github.com/odoo/odoo/blob/a74684777c27e26639b75b0668bb15afadb78c4f/addons/product/models/product_template.py#L186-L188 In the `RecordSet`'s context, `bin_size=True`, so accessing `image_<size>` returns a size instead of a binary. `_compute_can_image_1024_be_zoomed` calls `tools.is_image_size_above` with this binary size, while the method expects the full base64 encoded image. Ultimately, this causes `base64.b64decode` to crash with the above error. **FIX** Update the `RecordSet`'s context to `bin_size=False`. Accessing `image_<size>` from the `RecordSet` will then return the full binary instead of the size. **NOTES** In versions <17.0, read and write were done in separate network calls causing the recompute to happen during the flush of the write, which doesn't have `bin_size=True` in the context. Because the field is stored, the read will not cause a recompute and thus avoids any error. In >=17.0, because the read occurs before the flush, and the write has invalidated the field, the recompute will occur with the context of the read (`bin_size=True`), causing the issue. opw-4413647 closes odoo#192047 Signed-off-by: Samiul Hoque (saho) <saho@odoo.com>
Changing a product template's image with the
can_image_1024_be_zoomed
field present in the view produces a crash on save.STEPS TO REPRODUCE
can_image_1024_be_zoomed
fieldThe product will be updated, but this error will be thrown:
CAUSE
odoo/addons/product/models/product_template.py
Lines 186 to 188 in a746847
In the
RecordSet
's context,bin_size=True
, so accessingimage_<size>
returns a size instead of a binary._compute_can_image_1024_be_zoomed
callstools.is_image_size_above
with this binary size, while the method expects the full base64 encoded image. Ultimately, this causesbase64.b64decode
to crash with the above error.FIX Update the
RecordSet
's context tobin_size=False
. Accessingimage_<size>
from theRecordSet
will then return the full binary instead of the size.NOTES
In versions <17.0, read and write were done in separate network calls causing the recompute to happen during the flush of the write, which doesn't have
bin_size=True
in the context. Because the field is stored, the read will not cause a recompute and thus avoids any error. In >=17.0, because the read occurs before the flush, and the write has invalidated the field, the recompute will occur with the context of the read (bin_size=True
), causing the issue.opw-4413647