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

Closed
wants to merge 2 commits into from

Conversation

andreabak
Copy link
Contributor

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.

@andreabak andreabak force-pushed the master-ir_exports_fix-abt branch from 8fd6ad7 to 44a6787 Compare May 23, 2024 20:58
@pauloamed
Copy link
Contributor

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
Contributor

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
@aj-fuentes aj-fuentes force-pushed the master-ir_exports_fix-abt branch from 44a6787 to 35e5935 Compare June 14, 2024 10:14
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 pushed a fixup commit with some suggestions (it was simpler to just push it than write them ;)) for the documentation. resolve_model_fields_path can be made public, there is no online documentation for helpers.py, since we are already spending time writing it let's add it in a publish-ready fashion :)

Also I think the order of the commits should be inverted. Add first the new util resolve_model_fields_path, then on the second commit improve the handling of the ir.exports records.

I will go over the code again, but I think it looks good already.

@aj-fuentes aj-fuentes force-pushed the master-ir_exports_fix-abt branch from 35e5935 to 32b3f49 Compare June 14, 2024 10:20
@andreabak andreabak force-pushed the master-ir_exports_fix-abt branch from 32b3f49 to 045f760 Compare June 14, 2024 13: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.

Some comments mostly to simplify the patch. I still believe it looks correct :)

Please double check anything I suggest, all is untested.

@aj-fuentes aj-fuentes force-pushed the master-ir_exports_fix-abt branch 8 times, most recently from e068fca to 70cdb94 Compare June 18, 2024 08:22
@andreabak andreabak force-pushed the master-ir_exports_fix-abt branch from 70cdb94 to 38ab91e Compare June 18, 2024 09:35
@aj-fuentes aj-fuentes force-pushed the master-ir_exports_fix-abt branch 3 times, most recently from 9124918 to 864afe0 Compare June 19, 2024 07:38
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Co-authored-by: Alvaro Fuentes <[email protected]>
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.

Co-authored-by: Alvaro Fuentes <[email protected]>
@aj-fuentes aj-fuentes force-pushed the master-ir_exports_fix-abt branch from 864afe0 to 8ab6d19 Compare June 19, 2024 07:39
Copy link
Contributor

@KangOl KangOl left a comment

Choose a reason for hiding this comment

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

Great works to both of you.
@robodoo rebase-ff r+

@robodoo
Copy link
Contributor

robodoo commented Jun 20, 2024

Merge method set to rebase and fast-forward.

robodoo pushed a commit that referenced this pull request Jun 20, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
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.

closes #84

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
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.

closes #84

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
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.

closes #84

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
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.

closes #84

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 20, 2024
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.

closes #84

Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
@robodoo
Copy link
Contributor

robodoo commented Jun 20, 2024

@andreabak @KangOl staging failed: ci/runbot on b88db5dce2ebcb778ffbb0d08ccb108c7a8ff940 (view more at https://runbot.odoo.com/runbot/build/64352686)

@KangOl
Copy link
Contributor

KangOl commented Jun 21, 2024

@robodoo retry

robodoo pushed a commit that referenced this pull request Jun 21, 2024
It is a common occurrence to have models metadata values that use a
"path of fields" approach (e.g. fields depends, domains, server actions,
import/export templates, etc.) and to effectively resolve those with all
the intermediate model+fields references of the path parts, either a
for loop is used in python, issuing multple queries, or a recursive CTE
query that does that resolution entirely within PostgreSQL.

In this commit a new `resolve_model_fields_path` helper is introduced
using a recursive CTE to replace some older code using the python-loop
approach.
An additional `FieldsPathPart` named tuple type is added to represent
information of the resolved part of a fields path, and the helper will
return a list of these for callers to then act upon.

Part-of: #84
Signed-off-by: Christophe Simonis (chs) <[email protected]>
Co-authored-by: Alvaro Fuentes <[email protected]>
@robodoo robodoo closed this in 5b944f7 Jun 21, 2024
@robodoo robodoo added the 17.4 label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants