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] fields: add convert_to_cache method in id class in fields #162978

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

alsh-odoo
Copy link
Contributor

This traceback occurs when the user tries to give a string as the default value through Studio.

To reproduce this issue:

  1. Install studio and inventory module
  2. Open any product in studio mode
  3. Activate show invisible elements from views in the studio sidebar
  4. Now click on id in form view and set the default value with any string
  5. A traceback occurs

Error:-

TypeError: '<' not supported between instances of 'int' and 'str

Because when the user gives a string as the default value
it tries to parse the field with the convert_to_cache method.

But in our case the ID class does not have the method convert_to_cache
so it gives the parse value as it is.

This leads to the above traceback when the default value (string) tries to compare with integers.

try:
model = self.env[model_name]
field = model._fields[field_name]
parsed = field.convert_to_cache(value, model)
json_value = json.dumps(value, ensure_ascii=False)
except KeyError:
raise ValidationError(_("Invalid field %s.%s") % (model_name, field_name))
except Exception:
raise ValidationError(_("Invalid value for %s.%s: %s") % (model_name, field_name, value))
if field.type == 'integer' and not (-2**31 < parsed < 2**31-1):

sentry-5193548638

@robodoo
Copy link
Contributor

robodoo commented Apr 23, 2024

@C3POdoo C3POdoo added the RD research & development, internal work label Apr 23, 2024
This traceback occurs when the user tries to give a string as the default value
through studio.

To reproduce this issue:

1) Install studio and inventory module
2) Open any product in studio mode
3) Activate 'show invisible elements' from views in the studio sidebar
4) Now click on id in from viewand set the default value as a string
5) A traceback occurs

Error:- "TypeError: '<' not supported between instances of 'int' and 'str'"

Because when the user gives a string as default value it tries to parse
the field with the 'convert_to_cache' method.

But in our case the ID class does not have the method 'convert_to_cache'
so it gives the parse value as it is.

This leads to the above traceback when the default value (string) is tries to
compare with integers.

https://github.com/odoo/odoo/blob/871121ab4a7a4ed5fc309823c5c41ccfeff7536d/odoo/addons/base/models/ir_default.py#L73-L82

sentry-5193548638
@alsh-odoo alsh-odoo force-pushed the 16.0-sentry-5193548638-typeerror-ir-default-alsh branch from cf0fa7e to 88d90be Compare April 23, 2024 12:07
@alsh-odoo alsh-odoo changed the title [FIX] fields: fix traceback when user gives string as default value for ID in studio [FIX] fields: add convert_to_cache method in id class in fields Apr 24, 2024
@alsh-odoo
Copy link
Contributor Author

Hello @odoo/sentry_reviewers

Can I have your review on this PR.

Thank You 🙂

@adwid
Copy link
Contributor

adwid commented Apr 24, 2024

Too invasive for an edge (and a bit stupid, let's be honest) case

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