-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
[13.0][FIX] dms: Set res_mimetype correctly in files #131
[13.0][FIX] dms: Set res_mimetype correctly in files #131
Conversation
Hi @victoralmau! Thank you very much for this contribution. As the addon you are improving does not have a declared maintainer, I take the opportunity to mention that you can consider adopting it. To do so, please read the maintainer role description, and, if interested, create a pull request to add your GitHub login to the |
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 we really need this, as this is very partial, but deploy properly a library that detects all the possible mimetypes instead of the limited implementation inside Odoo. Please check this code:
Try in your local to put such library to see if it's detected properly, and if so we should:
- Add in base Doodba such library
- Put in the README in the installation section the recommendation to install the library.
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.
As @pedrobaeza said, the first thing to try is to install those libraries and see if the problem goes away automatically. If that happens, close this.
Otherwise, a couple of code comments below.
dms/models/dms_file.py
Outdated
def _compute_mimetype(self): | ||
""" Similar to addons/base/models/ir_attachment.py#L232 """ |
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 comment says nothing. And the line number can change. Please add a proper docstring and, if you need to refer to another resource, add a permalink.
dms/models/dms_file.py
Outdated
record.res_mimetype = mimetypes.guess_type(record.name or "")[0] | ||
if record.res_mimetype == "application/octet-stream": | ||
record.res_mimetype = guess_mimetype( | ||
base64.b64decode(record.content or "") | ||
) |
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.
IIUC, you're trying to get the mimetype from the file name and, later, from the file contents.
IMHO it should be the opposite. The contents are usually more reliable than the file extension to know the kind of file you have.
I tested locally to add the Now the question is, do we add it as a dependency in the manifest or do we suggest its installation in the readme file and skip the parts of the test that are necessary if the library is not added? Let's not forget that this happened because the |
See my previous comment in #131 (review) |
f70cab2
to
5ab267b
Compare
Changes done. |
IMO we should add it for all (as it affects also to non DMS users that attach a video in chatter), but meanwhile we can add it to current instances through the regular way. cc @yajo |
5ab267b
to
c563bcd
Compare
def test_content_file_res_mimetype_magic_library(self): | ||
if not magic: | ||
self.skipTest("Without python-magic library installed") |
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.
FTR there's a decorator for this: https://docs.python.org/3/library/unittest.html#unittest.skipIf
However it's OK as it is 😊
/ocabot merge patch |
Hey, thanks for contributing! Proceeding to merge this for you. |
@yajo your merge command was aborted due to failed check(s), which you can inspect on this commit of 13.0-ocabot-merge-pr-131-by-Yajo-bump-patch. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
Improves Odoo mime type detection out of the box. See https://github.com/odoo/odoo/blob/2dfa8fd0022b0a1fc97b721b3b8c3dd4f28889b3/odoo/tools/mimetypes.py#L164-L173 and the full story from OCA/dms#131.
Improves Odoo mime type detection out of the box. See https://github.com/odoo/odoo/blob/2dfa8fd0022b0a1fc97b721b3b8c3dd4f28889b3/odoo/tools/mimetypes.py#L164-L173 and the full story from OCA/dms#131.
Failed due to odoo/odoo#75387. |
Hello @yajo, you could use OCA/l10n-brazil@d43e0eb |
This PR has the |
/ocabot merge patch It can be fw-port it to v14 as well |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at 8ae4aff. Thanks a lot for contributing to OCA. ❤️ |
Improves Odoo mime type detection out of the box. See https://github.com/odoo/odoo/blob/2dfa8fd0022b0a1fc97b721b3b8c3dd4f28889b3/odoo/tools/mimetypes.py#L164-L173 and the full story from OCA/dms#131. (cherry picked from commit 2332a53)
Set
res_mimetype
correctly in files.Please @yajo and @pedrobaeza can you review it?
@Tecnativa TT31461