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] util.fields: handle ir.exports model/fields renames/removal #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andreabak
Copy link
Collaborator

Properly handle ir.exports, especially on model/fields removal.

See commits for additional details.

@andreabak andreabak requested review from KangOl, aj-fuentes and a team May 15, 2024 11:16
@robodoo
Copy link
Contributor

robodoo commented May 15, 2024

@andreabak andreabak force-pushed the master-ir_exports_fix-abt branch 2 times, most recently from a4fc2be to 8fd6ad7 Compare May 17, 2024 10:52
Copy link
Contributor

@aj-fuentes aj-fuentes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the base idea of this PR is nice. The current implementation seems like doing too much for a first version. My suggestions are mostly to simplify the idea and focus on the simplest solution that work. If we encounter performance issues then we can switch to alternatives, probably reusing ideas already here.

src/util/helpers.py Outdated Show resolved Hide resolved
src/util/helpers.py Outdated Show resolved Hide resolved
src/util/report.py Outdated Show resolved Hide resolved
src/util/report-migration.xml Outdated Show resolved Hide resolved
)


def get_resolved_ir_exports(cr, models=None, fields=None, only_missing=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be made simpler. Perform a couple of queries to get the pairs model,path that need processing then use the _resolve_model_fields_path with them.

I find it odd to have this util in fields.py, maybe helpers.py would be better suited?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no perfect place to put it. For models-specific helpers I see accounting, domains modules, views are scattered between snippets and records (until #23 moves forward), there's some server actions helpers in fields.
I'm not sure what data module is for?
Perhaps records could also be considered?
But I guess helpers is an okay compromise (also to not mess with imports too much).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be records.py indeed. But I'm not sure myself. @KangOl ?

Implement proper fixing and/or removal of ir.exports and
ir.exports.line records on model/fields renames/removal:
- renamed fields: update affected ir.exports.line records
- removed fields: remove affected ir.exports.line records
- renamed models: update affected ir.exports records `resource`
- removed models: remove affected ir.exports.line / ir.exports records

Some of these cases were already handled but have been improved.

Specifically:
- for renamed fields, previously was done by doing a simple string
  replacement, which is not good enough because export lines can
  reference fields paths, and these in turn *might* contain paths to
  multiple fields with the same name on different models, only some of
  which are affected. Now the fields path get properly resolved for
  renaming, only the affected fields path parts are updated.
- for removed fields, previously no action was taken, leaving a broken
  export template and UI traceback. Now the affected export lines are
  removed, using fields paths resolution.
- for renamed and removed models, this was already handled by the
  indirect_references mechanism, but now export lines for the removed
  models are checked with the same mechanism for fields above.

Additionally, unit tests have been added to make sure these cases are
properly handled by the code.
The newly added ir.exports fixing code uses a recursive CTE query to
resolve fields paths (from a root model). Similar code is already
existing for handling domains, `ir.model.fields`.`depends`, and
`ir.act.server`.`update_path`; but this older code is using a python
for loop and issuing multiple queries to resolve the paths.

In this commit, some of those helpers code is refactored to use the
newer recursive CTE query instead.

Additionally, the `_resolve_model_fields_path` helper and related code
has been moved to `util.helpers` module.
@pauloamed
Copy link

Hey, such a nice PR.
I'm facing a similar issue with base_import.mapping (eg. upg-1586781)!

I've got some entries in base_import.mapping that have deleted fields in column_name column, what leads to a positive matching when importing a file table with columns with such deleted fields.
This positive matching is returned in the parse_preview RPC call and leads to an infinite loop in the JS code.

@pauloamed
Copy link

Hey, such a nice PR. I'm facing a similar issue with base_import.mapping (eg. upg-1586781)!

I've got some entries in base_import.mapping that have deleted fields in column_name column, what leads to a positive matching when importing a file table with columns with such deleted fields. This positive matching is returned in the parse_preview RPC call and leads to an infinite loop in the JS code.

Forgot to ping you guys sorry @andreabak @aj-fuentes

@andreabak andreabak requested a review from aj-fuentes June 3, 2024 07:46
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.

None yet

4 participants