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

Python 3.9 fixes, auth option for webdav, fixed stored filename #285

Closed

Conversation

wpichler
Copy link
Contributor

@wpichler wpichler commented Oct 5, 2023

Hi all,

three small fixes for some small problems...

[FIX] Small fix to reformat the auth option as tuple for protocol webdav. It is not possible to specify a tuple in json !
[FIX] Fixed the stored filename to include the path. Without this you are not able to store files in custom sub directories
[FIX] Added future import annotations to be python 3.9 compatible

@OCA-git-bot
Copy link
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

@wpichler wpichler force-pushed the 16.0-fix_missing_future_annotations branch from 752f2e9 to 838337a Compare October 5, 2023 13:33
@@ -456,7 +457,7 @@ def _enforce_meaningful_storage_filename(self) -> None:
# we need to update the store_fname with the new filename by
# calling the write method of the field since the write method
# of ir_attachment prevent normal write on store_fname
attachment._force_write_store_fname(f"{storage}://{new_filename}")
attachment._force_write_store_fname(f"{storage}://{new_filename_with_path}")
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@wpichler The name should not contains the directory path defined on the backend.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

If you nest your filesystem into 'rooted_dir' filesystem, the path given as parameter to the rooted_dir must not appear into the store_fname. (When you define a directory_path on your backend,
your filesystem is nested into a rooted_dir filesystem. This nesting could be done on multiple levels)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lmignon I do see problems here - there is a function _get_fs_path - which does allow to optimize the filesystem path (by adding a sub directory). I did use this function (with a monkey patch) to create record depended file system paths (so the pdf generated for the invoice gets as path "Out-Invoice/2023/January/filename.pdf" - gets stored in nextcloud - so available in a nice directory structure for the end user).

The function _get_fs_path get used in _storage_file_write

_storage_file_read does use _fs_parse_store_fname - this function does work with the store_fname - and will not use _get_fs_path !

_file_open - does use _get_fs_parts - this does use _fs_parse_store_fname - so also no _get_fs_path

So the problem i got was - the file was stored in "some/path/filename" - but the system could not read the file - because the store_fname does not had the path - and the read functions do not use the _get_fs_path function to restore the path for reading.

So - why not store the path with store_fname ? I did this change - and it does work like a charm.

Copy link
Sponsor Contributor

@lmignon lmignon Oct 6, 2023

Choose a reason for hiding this comment

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

I think we can manage-it by determining which part of the path is related to the nested rooted_dir filesystem and only remove this part of the path from the new_filename_with_path... A rooted_dir has a path attribute and a fs attribute...

something like.....

# rooted_dir path computation...
rooted_paths = []
rooted_dir_fs = fs

while rooted_dir_fs and hasattr(rooted_dir_fs, "path"):
    rooted_paths.append(rooted_dir_fs.path)
    rooted_dir_fs = getattr(rooted_dir_fs, "fs", None)
    
rooted_paths.reverse()
rooted_path = "/".join(rooted_paths)

new_filename = new_filename_with_path.replace(rooted_path, "")

In any cases, we must add unit tests for such a cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've applied your code (with comments that code is coming from your side....) - tested it - does work fine for me.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

We need unit tests. IMO, the code could be extracted into a model method on fs.storage.

@@ -1,6 +1,7 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from __future__ import annotations
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

By default, all oca addons are tested with py 3.10 and odoo 16 itself is tested on py 3.10. You should use py 3.10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah - but odoo 16 does also work with python 3.9 - even the default docker Dockerfile does use debian bullseye - which is based on python 3.9.
And other modules in the repo do already use this future import - so it should be consistent across the modules.

@lmignon lmignon added this to the 16.0 milestone Oct 5, 2023
lmignon added a commit to acsone/storage that referenced this pull request Oct 9, 2023
Add history for commit included from OCA#285 and the author to the contributors list
lmignon added a commit to acsone/storage that referenced this pull request Oct 9, 2023
Add history for commit included from OCA#285 and the author to the contributors list
lmignon added a commit to acsone/storage that referenced this pull request Oct 9, 2023
Add history for commit included from OCA#285 and the author to the contributors list
@lmignon
Copy link
Sponsor Contributor

lmignon commented Oct 9, 2023

@wpichler To move forward with the 2 validated commits regarding the support for python3.9 and the fix for webdav, I cherry picked the two commits into #286, fixed pre-commit and added a release note. Your 2 fixes will be included into the next release.

@lmignon
Copy link
Sponsor Contributor

lmignon commented Oct 9, 2023

The part regarding the path preservation has to be refined. (unittests, ...)

@wpichler wpichler force-pushed the 16.0-fix_missing_future_annotations branch from 5fea8e7 to 4743337 Compare October 10, 2023 06:26
… are not able to store files in custom sub directories

[FIX] Do take nested rooted fs paths into account in computation of store_fname. Code by @lmignon - Laurent Mignon (ACSONE)
@wpichler wpichler force-pushed the 16.0-fix_missing_future_annotations branch from 4743337 to 45f4272 Compare October 10, 2023 06:31
amh-mw pushed a commit to amh-mw/oca-storage that referenced this pull request Oct 23, 2023
Add history for commit included from OCA#285 and the author to the contributors list
amh-mw pushed a commit to amh-mw/oca-storage that referenced this pull request Oct 23, 2023
Add history for commit included from OCA#285 and the author to the contributors list
amh-mw pushed a commit to metricwise/oca-storage that referenced this pull request Oct 23, 2023
Add history for commit included from OCA#285 and the author to the contributors list
marcelsavegnago pushed a commit to Escodoo/storage that referenced this pull request Nov 28, 2023
Add history for commit included from OCA#285 and the author to the contributors list
marcelsavegnago pushed a commit to Escodoo/storage that referenced this pull request Dec 1, 2023
Add history for commit included from OCA#285 and the author to the contributors list
@len-foss
Copy link
Contributor

Hello Laurent!

First, this is a great implementation of the storage concept and I hope there will be little issue with porting modules.

It's been working like a charm, except for the paths issue, which breaks everything.

I started working on an implementation of your proposed solution, putting that code snippet in a function. In our test case we had a rooted directory part before the filesystem path - basically for a thumbnail the rooted path is "odoo/attachments" and the added path will be something like "53/2b". But, it turns out that the 'rooted_path' was never a problem in our tests.
In other words, the diff you suggest, although more complicated, does exactly the same thing.

Are you fine with the simple diff if there's a test case checking for the rooted path issue?

@len-foss
Copy link
Contributor

By the way @wpichler, actually commit ef68e0d wasn't necessary, you could simply state:
{"base_url": "https://username:password@host.tld/remote.php/webdav"}
As you can see in the documentation:
https://www.python-httpx.org/advanced/#authentication

Although it's not very intuitive so it might be good to have some doc in the future.

@lmignon
Copy link
Sponsor Contributor

lmignon commented Dec 11, 2023

Are you fine with the simple diff if there's a test case checking for the rooted path issue?

No sure what you suggest. Nevertheless a test case with the fix has more chance to be merged than a fix without tests 😏

john-herholz-dt pushed a commit to DeineTuer-GmbH/OCA_storage that referenced this pull request Jan 16, 2024
Add history for commit included from OCA#285 and the author to the contributors list
nguyenminhchien pushed a commit to nguyenminhchien/storage that referenced this pull request Feb 22, 2024
Add history for commit included from OCA#285 and the author to the contributors list
nguyenminhchien pushed a commit to nguyenminhchien/storage that referenced this pull request Mar 11, 2024
Add history for commit included from OCA#285 and the author to the contributors list
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