-
Notifications
You must be signed in to change notification settings - Fork 42
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
[IMP] util.remove_view : remove redundant t-calls #116
base: master
Are you sure you want to change the base?
Conversation
f3943de
to
13fa9cb
Compare
761da84
to
67feba3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address pre-commit
src/util/records.py
Outdated
if module and module not in standard_modules or not module: | ||
_logger.info( | ||
"The view %s with ID: %s has been updated, removed block with t-call for depricated view %s", | ||
('"' + module + '.' + name + '"' if module else ""), | ||
vid, | ||
xml_id, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. We generally don't touch custom code, it's up to the client to adapt their views. Imho you should limit your query fetching the views to standard_modules
(but including studio
views).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We update all views when fields are removed, it may make sense to remove t-calls for views we are removing. But then this means that we would probably want to rename t-calls when we rename an xmlid of a view. @KangOl wdyt?
67feba3
to
3e4f381
Compare
src/util/records.py
Outdated
SELECT iv.id,imd.module,imd.name | ||
FROM ir_ui_view iv | ||
LEFT JOIN ir_model_data imd | ||
ON iv.id = imd.res_id AND imd.model = 'ir.ui.view' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ON iv.id = imd.res_id AND imd.model = 'ir.ui.view' | |
ON iv.id = imd.res_id | |
AND imd.model = 'ir.ui.view' |
src/util/records.py
Outdated
FROM ir_ui_view iv | ||
LEFT JOIN ir_model_data imd | ||
ON iv.id = imd.res_id AND imd.model = 'ir.ui.view' | ||
WHERE {} ~ 't-call="{}"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHERE {} ~ 't-call="{}"' | |
WHERE {} ~ '\yt-call=(["'']){}\1"' |
src/util/records.py
Outdated
) | ||
for vid, module, name in cr.fetchall(): | ||
with edit_view(cr, view_id=vid) as arch: | ||
node = arch.find('.//t[@t-call="' + xml_id + '"]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node = arch.find('.//t[@t-call="' + xml_id + '"]') | |
node = arch.find(".//t[@t-call='{}']".format(xml_id)) |
src/util/records.py
Outdated
standard_modules = set(modules.get_modules()) - {"studio_customization"} | ||
if module and module not in standard_modules or not module: | ||
_logger.info( | ||
"The view %s with ID: %s has been updated, removed block with t-call for depricated view %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The view %s with ID: %s has been updated, removed block with t-call for depricated view %s", | |
"The view %s with ID: %s has been updated, removed block with t-call for deprecated view %s", |
src/util/records.py
Outdated
if node is not None: | ||
node.getparent().remove(node) | ||
standard_modules = set(modules.get_modules()) - {"studio_customization"} | ||
if module and module not in standard_modules or not module: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified as
if module and module not in standard_modules or not module: | |
if not module or module not in standard_modules: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @KangOl, suggested changes done could you please have a look? thanks :)
3e4f381
to
77b0f22
Compare
Thank you for your valuable input @diagnoza, @aj-fuentes and @KangOl. |
src/util/records.py
Outdated
standard_modules = set(modules.get_modules()) - {"studio_customization"} | ||
if not module or module not in standard_modules: | ||
_logger.info( | ||
"The view %s with ID: %s has been updated, removed block with t-call for deprecated view %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The view %s with ID: %s has been updated, removed block with t-call for deprecated view %s", | |
"The view %s with ID: %s has been updated, removed a t-call to a deprecated view %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @diagnoza , Changes have been made, Could you please review it back @aj-fuentes @KangOl
eebe33a
to
d746716
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle I'm OK with this. I will check with @KangOl once he's back if we should also do something similar for xmlid renames.
src/util/records.py
Outdated
standard_modules = set(modules.get_modules()) - {"studio_customization"} | ||
for vid, module, name in cr.fetchall(): | ||
with edit_view(cr, view_id=vid) as arch: | ||
node = arch.find(".//t[@t-call='{}']".format(xml_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have more than one t-call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
src/util/records.py
Outdated
r""" | ||
SELECT iv.id, imd.module, imd.name | ||
FROM ir_ui_view iv | ||
LEFT JOIN ir_model_data imd | ||
ON iv.id = imd.res_id | ||
AND imd.model = 'ir.ui.view' | ||
WHERE {} ~ '\yt-call=(["'']){}\1' | ||
""".format(arch_col, xml_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r""" | |
SELECT iv.id, imd.module, imd.name | |
FROM ir_ui_view iv | |
LEFT JOIN ir_model_data imd | |
ON iv.id = imd.res_id | |
AND imd.model = 'ir.ui.view' | |
WHERE {} ~ '\yt-call=(["'']){}\1' | |
""".format(arch_col, xml_id) | |
format_query(cr, """ | |
SELECT iv.id, imd.module, imd.name | |
FROM ir_ui_view iv | |
LEFT JOIN ir_model_data imd | |
ON iv.id = imd.res_id | |
AND imd.model = 'ir.ui.view' | |
WHERE {} ~ %s""", arch_col | |
), | |
[r"""\yt-call=(["']){}\1""".format(xml_id)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @aj-fuentes and @KangOl
Changes have been made. Could you please confirm them?
6036e6b
to
20793ea
Compare
Note that |
5d985e6
to
0f26f72
Compare
Hello @KangOl, |
upgradeci retry with always hr |
Hello @KangOl, |
Can you please add a test? |
e9489d4
to
624e52c
Compare
Hello @KangOl, I have added unit test for remove_view. Could you please review it? |
Hello @KangOl, |
The |
624e52c
to
eb9b3de
Compare
Hello @KangOl, |
Hello @KangOl, |
Gentle reminder @KangOl |
Hello @KangOl |
src/util/records.py
Outdated
@@ -1622,3 +1635,46 @@ def remove_act_window_view_mode(cr, model, view_mode): | |||
""", | |||
[view_mode, model, view_mode, view_mode], | |||
) | |||
|
|||
|
|||
def remove_redudant_tcalls(cr, match=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the name, also make this method private, is not something we
def remove_redudant_tcalls(cr, match=None): | |
def _remove_redundant_tcalls(cr, match): |
Why having a default value for match
?
src/util/records.py
Outdated
if xml_id != "?" or key: | ||
if xml_id != key: | ||
remove_redudant_tcalls(cr, xml_id) | ||
remove_redudant_tcalls(cr, key) | ||
else: | ||
remove_redudant_tcalls(cr, xml_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be made more direct. Also if xml_id is ? you don't need to remove by xml_id.
if xml_id != "?" or key: | |
if xml_id != key: | |
remove_redudant_tcalls(cr, xml_id) | |
remove_redudant_tcalls(cr, key) | |
else: | |
remove_redudant_tcalls(cr, xml_id) | |
if xml_id != "?": | |
remove_redundant_tcalls(cr, xml_id) | |
if key and key != xml_id: | |
remove_redundant_tcalls(cr, key) |
src/util/records.py
Outdated
"The view %s with ID: %s has been updated, removed a t-call to a deprecated view %s", | ||
('"{}.{}"'.format(module, name) if module else ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The view %s with ID: %s has been updated, removed a t-call to a deprecated view %s", | |
('"{}.{}"'.format(module, name) if module else ""), | |
"The view %swith ID: %s has been updated, removed t-calls to deprecated %r", | |
("`{}.{}` ".format(module, name) if module else ""), |
src/util/records.py
Outdated
SELECT iv.id, imd.module, imd.name | ||
FROM ir_ui_view iv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT iv.id, imd.module, imd.name | |
FROM ir_ui_view iv | |
SELECT iv.id, | |
imd.module, | |
imd.name | |
FROM ir_ui_view iv |
eb9b3de
to
6afb5a5
Compare
Hello @aj-fuentes, suggested changes done could you please have a look? thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments
src/util/records.py
Outdated
""", | ||
sql.SQL(arch_col), | ||
), | ||
[r"""\yt-call=(["'']){}\1""".format(match)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are passing the regexp as parameter you don't need to duplicate the single quote.
You need to regexp escape match
otherwise .
will match any character. Since you anyway do a xmlnode.findall
later this won't at least cause wrong upates. But you can decrease the output of the query by escaping the .match
[r"""\yt-call=(["'']){}\1""".format(match)], | |
[r"""\yt-call=(["']){}\1""".format(re.escape(match))], |
src/util/records.py
Outdated
This function removes the t-call of the removed view from all types of views | ||
based on xml_id and key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function removes the t-call of the removed view from all types of views | |
based on xml_id and key. | |
This function removes the t-calls to `match`. |
src/util/records.py
Outdated
This function removes the t-call of the removed view from all types of views | ||
based on xml_id and key. | ||
|
||
:param str match: contains xml_id or key based on argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param str match: contains xml_id or key based on argument | |
:param str match: t-calls value to remove, typically it would be a view's xml_id or key |
6afb5a5
to
b9f0a16
Compare
Thank you for your valuable input @aj-fuentes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cc: @KangOl
Hello @KangOl, |
@KangOl Waiting for your final review as @aj-fuentes has approved this PR. Thanks! |
I would also adapt |
while removing the view, removing the content having t-call in other views which are calling to have the content of it. As there are many specific fixes available for this, it's better to handle it in remove_view. Before fix: t-call with the same xml_id will remain in other views that are using it. So during access of that view, the system is raising an error "view not found." ``` <t name="Payment" t-name="website_sale.payment"> <t t-call="website_sale.cart_summary"/> </t> ``` After fix: t-call will be removed, so no error will be raised. ``` <t name="Payment" t-name="website_sale.payment"> </t> ``` Traceback: ``` Error while render the template ValueError: View 'website_sale.cart_summary' in website 1 not found Template: website_sale.payment Path: /t/t/div/div[1]/div/div[4]/div[1]/t Node: <t t-call="website_sale.address_on_payment"/> ```
Testcases for remove_view and rename_xmlid
b9f0a16
to
4daaa9a
Compare
Hello @KangOl @aj-fuentes |
src/util/records.py
Outdated
UPDATE ir_ui_view | ||
SET {arch} = regexp_replace({arch}, %s, %s, 'g') | ||
WHERE {arch} ~ %s | ||
""".format(arch=arch_col), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use format_query
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @KangOl suggested changes done could you please have a look? thanks :)
When renaming a view, we should also update its references in other views where it is used in t-call, t-value and t-name attributes. This ensures consistency and prevents broken references in dependent views.
4daaa9a
to
9b1dbb4
Compare
Hello @KangOl |
Hello @KangOl cc: @aj-fuentes |
Hello @KangOl cc: @aj-fuentes |
While removing the view, removing the content having t-call in other views which are calling to have the content of it.
As there are many specific fixes available for this [16776,15322,14413,13404,13325,12205,12335 etc..], it's better to handle it in remove_view.
Before fix:
After fix:
Traceback: