Skip to content
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

[FIX] web: handle computed stored binary fields #156673

Closed

Conversation

reth-odoo
Copy link
Contributor

@reth-odoo reth-odoo commented Mar 6, 2024

Currently if you have a computed stored binary field, calling web_save will save the "bin_size" value to database instead of correctly storing the computed data.

Everything goes well until web_read triggers a re-compute with bin_size=True, this leads compute_value in class Binary(field) to store the "bin_size" value in cache.

As the compute from web_save has not yet been flushed by this point, the _write that happens after web_save is completed will use the new cache value instead of the one we want.

Issue is mitigated by flushing before the web_read.


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Mar 6, 2024

@C3POdoo C3POdoo added the RD research & development, internal work label Mar 6, 2024
@reth-odoo reth-odoo force-pushed the 17.0-example-binary-store-compute-reth branch from 64bc21d to 26cda0b Compare April 4, 2024 10:43
@reth-odoo reth-odoo marked this pull request as ready for review April 4, 2024 10:46
@reth-odoo reth-odoo force-pushed the 17.0-example-binary-store-compute-reth branch from 26cda0b to 0d23781 Compare April 4, 2024 10:46
@C3POdoo C3POdoo requested review from a team, xmo-odoo, ryv-odoo, Iucapad and juliusc2066 and removed request for a team April 4, 2024 10:47
@reth-odoo
Copy link
Contributor Author

reth-odoo commented Apr 4, 2024

@rco-odoo Hi, cwg proposed this fix for the issue but as he's on leave he suggested I ping you :)

Should normally be safe (still trying to figure out the one access error case), and it's especially useful as in most cases where you have a computed binary you probably want to store it to avoid having to recompute it every time (as I would guess most computed binaries should imply a heavy computation).

We need it for a new app that's supposed to target 17.0 so would be nice to merge it there, plus the issue is introduced in that version anyway.

Currently if you have a computed stored binary field calling `web_save`
will save the "bin_size" value to database instead of correctly storing
the computed data.

This is due to the cache being updated in web_read, at the end of web_save,
before the values of the create/write are ever flushed. As web_read is
called with bin_size=True for efficiency, this leads to _write using
the newly cached size as the value, instead of the value passed to web_save.
@reth-odoo reth-odoo force-pushed the 17.0-example-binary-store-compute-reth branch from 0d23781 to 9869551 Compare April 4, 2024 10:58
@ryv-odoo
Copy link
Contributor

ryv-odoo commented Apr 5, 2024

Hello @reth-odoo ,
IMO, it sounds strange that flush fixes the problem (and the description of your commit message doesn't convince me, sorry). I am currently investing the problem, but it looks like it is deeper than the web_save.

Proposal:#160708

@reth-odoo
Copy link
Contributor Author

and the description of your commit message doesn't convince me, sorry

That's fine, so long as we can find some kind of solution :p
Thanks for looking into it

@reth-odoo
Copy link
Contributor Author

fixed in ryv's proposal

@reth-odoo reth-odoo closed this Apr 23, 2024
rco-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Apr 26, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request Apr 26, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

closes #160708

Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request Apr 26, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

closes #160708

Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request Apr 26, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

closes #160708

Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Renaud Thiry <reth@odoo.com>
ryv-odoo added a commit to odoo-dev/odoo that referenced this pull request Apr 29, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request Apr 30, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

Part-of: #163634
Co-authored-by: Renaud Thiry <reth@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Apr 30, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

X-original-commit: 400790e
Co-authored-by: Renaud Thiry <reth@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Apr 30, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

X-original-commit: 400790e
Co-authored-by: Renaud Thiry <reth@odoo.com>
willylohws pushed a commit to willylohws/odoo that referenced this pull request May 1, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

closes odoo#160708

Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request May 8, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

X-original-commit: 400790e
Part-of: #164061
Co-authored-by: Renaud Thiry <reth@odoo.com>
robodoo pushed a commit that referenced this pull request May 8, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes #156673

X-original-commit: 400790e
Part-of: #164045
Co-authored-by: Renaud Thiry <reth@odoo.com>
zel-odoo pushed a commit to odoo-dev/odoo that referenced this pull request May 24, 2024
When bin_size=True is in the context, a computed non-attachment binary
is incorrectly saved to the database.  The row is actually updated with
the size of the binary instead of the value itself.

This commit fixes the problem by avoiding setting the cache with the
bin_size value as dirty.

Moreover, the binary size is computed with `pg_size_pretty` for
non-attachment binary fields.  Also, method compute_value() calls
b64decode() on the value that was previously encoded in base64 by
_compute_datas().  But _compute_datas() is specific to attachments, and
is not used in this case.  Thus b64decode() doesn't make sense.

These 3 bugs are now covered by testing web_save(), where cache
consistency is required. It was first reported for this method.

Closes odoo#156673

X-original-commit: 400790e
Part-of: odoo#164061
Co-authored-by: Renaud Thiry <reth@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants