Commit 7d3c55e2 authored by Jérome Perrin's avatar Jérome Perrin

BusinessTemplate: fix NameError on view when erp5_forge is not updated

This only happens in rare condition:
 * products where updated and ERP5VCS is moved to portal_components
 * everything is updated except erp5_forge
 * preferences for VCS working copies is set
parent f625f865
......@@ -5816,8 +5816,11 @@ Business Template is a set of definitions, such as skins, portal types and categ
# could be moved to Products.ERP5.Base.Base
try:
from erp5.component.module.WorkingCopy import NotAWorkingCopyError
except ImportError:
return False
try:
return self.getVcsTool().reference in vcs
except (ImportError, NotAWorkingCopyError):
except NotAWorkingCopyError:
return None in vcs
security.declareProtected(Permissions.ManagePortal, 'export')
......
  • I tried several approaches, but there's no regression test for this exact problem, because it happens only with "not fully" updated site.

    While trying to reproduce, I could improve a bit test coverage in !992 (merged) , !996 (merged) and !989 (merged) I was first thinking that this problem only happens when erp5_forge is not installed and we don't notice because testXHTMLStyle just check all business templates together, so I tried to run this html style on business templates one by one, to reproduce that situation when we don't have erp5_forge installed, but it's not enough to reproduce that problem.

    Pylint did not help here either. I tried other checkers, with this minimal reproduction:

    "repro for https://lab.nexedi.com/nexedi/erp5/commit/7d3c55e2a5a21223d46ccd661a7c2a7f4116fad4"
    try:
        from notexist import Error # type: ignore
    except (ImportError, Error):
        pass

    it fails at runtime

    Traceback (most recent call last):
      File "repro.py", line 3, in <module>
        from notexist import Error
    ImportError: No module named 'notexist'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "repro.py", line 4, in <module>
        except (ImportError, Error):
    NameError: name 'Error' is not defined

    Out of the tools I tried, only https://github.com/google/pytype recognize this error:

    $ for tool in pylint pyflakes mypy pytype ; do echo $tool ; $tool repro.py ; echo  ; done
    pylint
    
    --------------------------------------------------------------------
    Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
    
    
    pyflakes
    
    mypy
    Success: no issues found in 1 source file
    
    pytype
    Computing dependencies
    Analyzing 1 sources with 0 local dependencies
    ninja: Entering directory `/tmp/xxx/.pytype'
    [1/1] check repro
    FAILED: /tmp/xxx/.pytype/pyi/repro.pyi 
    pytype-single --imports_info /tmp/xxx/.pytype/imports/repro.imports --module-name repro -V 3.5 -o /tmp/xxx/.pytype/pyi/repro.pyi --analyze-annotated --nofail --quick /tmp/xxx/repro.py
    File "/tmp/xxx/repro.py", line 4, in <module>: Name 'Error' is not defined [name-error]
    
    For more details, see https://google.github.io/pytype/errors.html#name-error.
    ninja: build stopped: subcommand failed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment