← Back to Pull requests

[19.0][FIX] dms: don't crash computing the extension of unknown mimetypes #551

Merged
skanndar merged 2 files (8 lines) on Nov 30, 2026 15:36 UTC
View on GitHub
skanndar skanndar commented on Nov 20, 2026 15:44 UTC
Author

Problem

With python-magic installed (as in the official odoo:19 image), creating a dms.file whose name has no extension fails when its content is detected as a mimetype that Python's mimetypes module doesn't know, e.g. a shell script named deploy (text/x-shellscript):

TypeError: 'NoneType' object is not subscriptable
dms/tools/file.py, line 99, in guess_extension

Renaming such a file to a name without extension fails the same way. Other types in this case include Makefiles, RTF and Windows executables.

The crash is reachable since 96128e4, which started passing the mimetype and content to guess_extension().

Fix

  • tools/file.py: (mimetypes.guess_extension(mimetype) or "")[1:] in both places.

  • _compute_extension passed record.content (base64) to guess_extension(), which expects the binary, so its second guess was always made on base64 text (text/plain → txt). Decode it, for records with content only.
  • The extension stays empty for such files.

    Diff: 8 lines (+4 / -4) across 2 files Reviewer: victoralmau Review duration: 14392m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.18) × (1 − Review Confidence (0.74)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.18 · 8 lines diff across 2 files
    0.18
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.49 · 4 substantive comment(s)
    0.49
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    73%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.131
    Real PR Conversation Timeline
    4 comments
    dms/models/dms_file.py
    "```suggestion for record in self.filtered("content"): ```"
    clarifying weight: 0.45
    dms/models/dms_file.py
    "Done, thanks!"
    clarifying weight: 0.45
    dms/tools/file.py
    "So the changes to dms/tools.file.py aren't necessary after all, right?"
    clarifying weight: 0.45
    dms/tools/file.py
    "No, they're still needed: `filtered("content")` only skips records without content. A shell script named `deploy` has content, and its mimetype (`text/x-shellscript`) has no known extension in Python's `mimetypes`, so line 99 still raises the `TypeError`. I checked it: with only the model change, creating that file still fails. "
    clarifying weight: 0.45
    Reviewers
    Assignees
    skanndar skanndar
    Labels
    risk: low confidence: 73.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 17.6% (LOW) · Higher = larger blast radius
    17.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 73.6% · Lower = rushed or shallow review
    73.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%
    Repository