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

[ADD] fields/make_field_non_stored #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pirols
Copy link
Contributor

@Pirols Pirols commented Feb 6, 2025

opw-4502675

When a field becomes non-stored, the associated column must be removed during the upgrade.

Such removal may cause user-defined filters relying on such field to fail.

This commit factors the logic to clean fields' references in ir.filters out from remove_field into a new private helper method, which is then reused in remove_column, preventing the above mentioned issue.

Example of problem, with reproducer:

account.account's group_id field has become non-stored1 in 18.0, therefore:

  1. Create db in 17.0, with account installed;
  2. Create user-defined default filter on model account.account, with domain containing group_id. Example: {"group_by", ["group_id"]};
  3. Upgrade db to 18.0
  4. Open chart of account (and select filter, if not automatically selected)

Error should look something like the following:

RPC_ERROR

Odoo Server Error

Occured on localhost:8069 on model account.account and id 6 on 2025-02-06 09:34:41 GMT

Traceback (most recent call last):
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 1957, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 137, in retrying
    result = func()
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 1924, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 2172, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/src/odoo/18.0/odoo/addons/base/models/ir_http.py", line 329, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 727, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/src/odoo/18.0/addons/web/controllers/dataset.py", line 35, in call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/18.0/odoo/api.py", line 517, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
  File "/home/odoo/src/odoo/18.0/addons/web/models/models.py", line 243, in web_read_group
    groups = self._web_read_group(domain, fields, groupby, limit, offset, orderby, lazy)
  File "/home/odoo/src/odoo/18.0/addons/web/models/models.py", line 269, in _web_read_group
    groups = self.read_group(domain, fields, groupby, offset=offset, limit=limit,
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2858, in read_group
    rows = self._read_group(domain, annotated_groupby.values(), annotated_aggregates.values(), offset=offset, limit=limit, order=orderby)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 1973, in _read_group
    groupby_terms: dict[str, SQL] = {
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 1974, in <dictcomp>
    spec: self._read_group_groupby(spec, query)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2090, in _read_group_groupby
    sql_expr = self._field_to_sql(self._table, fname, query)
  File "/home/odoo/src/odoo/18.0/addons/account/models/account_account.py", line 184, in _field_to_sql
    return super()._field_to_sql(alias, fname, query, flush)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2946, in _field_to_sql
    raise ValueError(f"Cannot convert {field} to SQL because it is not stored")
ValueError: Cannot convert account.account.group_id to SQL because it is not stored

The above server error caused the following client error:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    Error: An error occured in the owl lifecycle (see this Error's "cause" property)
        at handleError (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:959:101)
        at App.handleError (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:1610:29)
        at ComponentNode.initiateRender (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:1051:19)

Caused by: RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:3134:163)
        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:3139:13)

Footnotes

  1. https://github.com/odoo/upgrade/blob/6197269809a7007fd7eadfc8fb6d2c6a83bc5ca4/migrations/account/saas~17.5.1.2/pre-migrate.py#L97

@Pirols Pirols requested review from KangOl and aj-fuentes February 6, 2025 09:52
@robodoo
Copy link
Contributor

robodoo commented Feb 6, 2025

Pull request status dashboard

@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch from d0b39e6 to b3e11b4 Compare February 6, 2025 09:57
src/util/pg.py Outdated Show resolved Hide resolved
@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch from 8671cfa to 8eacb4e Compare February 6, 2025 13:04
src/util/fields.py Outdated Show resolved Hide resolved
@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch 2 times, most recently from a714f59 to 8cf7e6b Compare February 6, 2025 13:17
@KangOl
Copy link
Contributor

KangOl commented Feb 6, 2025

upgradeci retry with always only hr

@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch 6 times, most recently from a907eb2 to 48c597c Compare February 11, 2025 13:58
@Pirols Pirols changed the title [FIX] pg/remove_column: clean filters [ADD] pg/make_field_non_stored Feb 11, 2025
@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch 4 times, most recently from 80b7c06 to d666964 Compare February 12, 2025 12:53
@Pirols Pirols changed the title [ADD] pg/make_field_non_stored [ADD] fields/make_field_non_stored Feb 12, 2025
@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch 2 times, most recently from 6b686df to 24d1103 Compare February 13, 2025 11:04
src/util/fields.py Outdated Show resolved Hide resolved
opw-4502675

When a field becomes non-stored, the associated column must be removed during
the upgrade.

Unless the field remains selectable, such removal will cause `ir.filters`
relying on such field to fail. This commit introduces a new util to clean up
user-defined filters. In order to do that, the relevant part of the
`remove_field` util is factored out into a new private method.

---

Example of problem, with reproducer:

`account.account`'s `group_id` field has become non-stored[^1] in 18.0,
therefore:

1. Create db in 17.0, with `account` installed;
2. Create user-defined default filter on model `account.account`, with domain
   containing `group_id`. Example: `{"group_by", ["group_id"]}`;
3. Upgrade db to 18.0
4. Open chart of account (and select filter, if not automatically selected)

Error should look something like the following:

```
RPC_ERROR

Odoo Server Error

Occured on localhost:8069 on model account.account and id 6 on 2025-02-06 09:34:41 GMT

Traceback (most recent call last):
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 1957, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "/home/odoo/src/odoo/18.0/odoo/service/model.py", line 137, in retrying
    result = func()
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 1924, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 2172, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/src/odoo/18.0/odoo/addons/base/models/ir_http.py", line 329, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/src/odoo/18.0/odoo/http.py", line 727, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/src/odoo/18.0/addons/web/controllers/dataset.py", line 35, in call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/18.0/odoo/api.py", line 517, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
  File "/home/odoo/src/odoo/18.0/addons/web/models/models.py", line 243, in web_read_group
    groups = self._web_read_group(domain, fields, groupby, limit, offset, orderby, lazy)
  File "/home/odoo/src/odoo/18.0/addons/web/models/models.py", line 269, in _web_read_group
    groups = self.read_group(domain, fields, groupby, offset=offset, limit=limit,
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2858, in read_group
    rows = self._read_group(domain, annotated_groupby.values(), annotated_aggregates.values(), offset=offset, limit=limit, order=orderby)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 1973, in _read_group
    groupby_terms: dict[str, SQL] = {
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 1974, in <dictcomp>
    spec: self._read_group_groupby(spec, query)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2090, in _read_group_groupby
    sql_expr = self._field_to_sql(self._table, fname, query)
  File "/home/odoo/src/odoo/18.0/addons/account/models/account_account.py", line 184, in _field_to_sql
    return super()._field_to_sql(alias, fname, query, flush)
  File "/home/odoo/src/odoo/18.0/odoo/models.py", line 2946, in _field_to_sql
    raise ValueError(f"Cannot convert {field} to SQL because it is not stored")
ValueError: Cannot convert account.account.group_id to SQL because it is not stored

The above server error caused the following client error:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    Error: An error occured in the owl lifecycle (see this Error's "cause" property)
        at handleError (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:959:101)
        at App.handleError (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:1610:29)
        at ComponentNode.initiateRender (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:1051:19)

Caused by: RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:3134:163)
        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/fd2cc33/web.assets_web.min.js:3139:13)
```

[^1]:
https://github.com/odoo/upgrade/blob/6197269809a7007fd7eadfc8fb6d2c6a83bc5ca4/migrations/account/saas~17.5.1.2/pre-migrate.py#L97
@Pirols Pirols force-pushed the master-clean_filters_upon_fields_column_removal-pied branch from 24d1103 to 1cf294b Compare February 13, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants