Skip to content

Conversation

mart-e
Copy link
Contributor

@mart-e mart-e commented Sep 15, 2023

Deprecate the usage of get_resource_path/get_module_resource. Using file_path has the same features with additional security checks.

Replace all the deprecated calls to open or get_resource_path with the file_open and file_path method.

Differences between get_resource_path and file_path:

  • get_resource_path returns False if the file does not exsits, file_path raises a FileNotFoundError
  • file_path ensures the file is within the addons-path

Difference between open and file_open

  • file_open ensures the file is within the addons-path

@robodoo
Copy link
Contributor

robodoo commented Sep 15, 2023

Pull request status dashboard

@C3POdoo C3POdoo added the RD research & development, internal work label Sep 15, 2023
@mart-e mart-e force-pushed the master-deprecate-module-paths-mat branch 27 times, most recently from f4c7812 to 923703f Compare September 18, 2023 09:47
@mart-e mart-e changed the title [WIP] use file_path and file_open [IMP] use file_path and file_open Sep 18, 2023
@mart-e mart-e force-pushed the master-deprecate-module-paths-mat branch from 5710352 to 2b04e14 Compare October 6, 2023 10:41
@mart-e
Copy link
Contributor Author

mart-e commented Oct 6, 2023

@robodoo r+ (hoping no longer having conflicts)

@robodoo
Copy link
Contributor

robodoo commented Oct 6, 2023

@mart-e linked pull request(s) odoo/enterprise#47475, odoo/upgrade#5187 not ready. Linked PRs are not staged until all of them are ready.

@mart-e mart-e force-pushed the master-deprecate-module-paths-mat branch from 2b04e14 to 1041c39 Compare October 6, 2023 12:08
Replace all the calls to get_resource_path to the better file_path or
directly use file_open when not needed

Doing both a get_resource_path and file_open means checking twice that
the file exists.
Doing a simple path concatenation before a file_open is safe.
If given to another method (e.g. etree.parse), calling file_path is
the prefered method.

Note that get_resource_path used to return False when the file does
not exists while file_path/file_open raises a FileNotFoundException
@mart-e mart-e force-pushed the master-deprecate-module-paths-mat branch from 1041c39 to d341891 Compare October 6, 2023 12:08
@mart-e
Copy link
Contributor Author

mart-e commented Oct 6, 2023

@robodoo r+ 🙄

robodoo pushed a commit that referenced this pull request Oct 6, 2023
file_path is superior and can replace every (often unnecessary) calls
Merge check_resource_path that is no longer needed

Part-of: #135607
robodoo pushed a commit that referenced this pull request Oct 6, 2023
Replace all the calls to get_resource_path to the better file_path or
directly use file_open when not needed

Doing both a get_resource_path and file_open means checking twice that
the file exists.
Doing a simple path concatenation before a file_open is safe.
If given to another method (e.g. etree.parse), calling file_path is
the prefered method.

Note that get_resource_path used to return False when the file does
not exists while file_path/file_open raises a FileNotFoundException

closes #135607

Related: odoo/upgrade#5187
Related: odoo/enterprise#47475
Signed-off-by: Martin Trigaux (mat) <[email protected]>
@robodoo robodoo temporarily deployed to merge October 6, 2023 15:50 Inactive
@robodoo robodoo closed this Oct 6, 2023
@robodoo robodoo added the 16.5 label Oct 6, 2023
@fw-bot fw-bot deleted the master-deprecate-module-paths-mat branch October 20, 2023 16:46
robodoo pushed a commit that referenced this pull request Jun 23, 2024
closes #135607

Signed-off-by: Martin Trigaux (mat) <[email protected]>
robodoo pushed a commit that referenced this pull request Jun 23, 2024
closes #135607

Signed-off-by: Martin Trigaux (mat) <[email protected]>
Salvio93 pushed a commit to Salvio93/Hoot-Integration that referenced this pull request May 22, 2025
Replace all the calls to get_resource_path to the better file_path or
directly use file_open when not needed

Doing both a get_resource_path and file_open means checking twice that
the file exists.
Doing a simple path concatenation before a file_open is safe.
If given to another method (e.g. etree.parse), calling file_path is
the prefered method.

Note that get_resource_path used to return False when the file does
not exists while file_path/file_open raises a FileNotFoundException

closes odoo/odoo#135607

Related: odoo/upgrade#5187
Related: odoo/enterprise#47475
Signed-off-by: Martin Trigaux (mat) <[email protected]>
@Armin-FalDiS
Copy link
Contributor

Hello @mart-e
This seems to have broken support for all non-png icons. Is there a reason for this or was this side-effect unintentional?

@mart-e
Copy link
Contributor Author

mart-e commented Jul 8, 2025

@Armin-FalDiS can you be a bit more specific? This commit changed a lot of things and was merged 2 years ago.

edit: oh I see, the ir_ui_menu.py part. Hmm it’s unintentional. We only have .png icons but we could support other image format if needed. Don’t hesitate to make a PR to patch this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
16.5 RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.