# Buggy code
def get_module(name):
    """
    Return module or None. Absolute import is required.

    :param (str) name: Dot-separated module path. E.g., 'scipy.stats'.
    :raise: (ImportError) Only when exc_msg is defined.
    :return: (module|None) If import succeeds, the module will be returned.

    """
    if name not in _not_importable:
        try:
            return import_module(name)
        except ImportError:
            _not_importable.add(name)


# Traceback (ValueError)
Traceback (most recent call last):
File "...\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "...\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "...\lib\site-packages\django\core\handlers\base.py", line 172, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "...\lib\site-packages\django\urls\resolvers.py", line 270, in resolve
for pattern in self.url_patterns:
File "...\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "...\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "...\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "...\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "...\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "....\urls.py", line 23, in <module>
from material.frontend import urls as frontend_urls
File "...\lib\site-packages\material\frontend\urls.py", line 7, in <module>
url(r'', include(modules.urls)),
File "...\lib\site-packages\material\frontend\registry.py", line 48, in urls
patterns.append(module.urls)
File "...\lib\site-packages\material\frontend\apps.py", line 98, in urls
return ModuleURLResolver(base_url, self.get_urls(), module=self, app_name=self.label, namespace=self.label)
File "...\lib\site-packages\material\frontend\apps.py", line 84, in get_urls
urls_module = import_module(urls_module_name)
File "...\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "app\urls.py", line 5, in <module>
from ... import views
File "app\views.py", line 27, in <module>
import plotly.offline as py
File "...\lib\site-packages\plotly\__init__.py", line 31, in <module>
from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
File "...\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
from . plotly import (
File "...\lib\site-packages\plotly\plotly\plotly.py", line 27, in <module>
from plotly import exceptions, files, session, tools, utils
File "...\lib\site-packages\plotly\tools.py", line 59, in <module>
ipython_core_display = optional_imports.get_module('IPython.core.display')
File "...\lib\site-packages\plotly\optional_imports.py", line 23, in get_module
return import_module(name)
File "...\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "...\lib\site-packages\IPython\__init__.py", line 48, in <module>
from .core.application import Application
File "...\lib\site-packages\IPython\core\application.py", line 24, in <module>
from IPython.core import release, crashhandler
File "...\lib\site-packages\IPython\core\crashhandler.py", line 28, in <module>
from IPython.core import ultratb
File "...\lib\site-packages\IPython\core\ultratb.py", line 111, in <module>
from IPython.core import debugger
File "...\lib\site-packages\IPython\core\debugger.py", line 36, in <module>
from IPython.utils import coloransi, io, py3compat
File "...\lib\site-packages\IPython\utils\io.py", line 78, in <module>
stdin = IOStream(sys.stdin, fallback=devnull)
File "...\lib\site-packages\IPython\utils\io.py", line 36, in __init__
for meth in filter(clone, dir(stream)):
File "...\lib\site-packages\IPython\utils\io.py", line 35, in clone
return not hasattr(self, meth) and not meth.startswith('_')
File "...\lib\site-packages\IPython\utils\io.py", line 70, in closed
return self.stream.closed
ValueError: underlying buffer has been detached

# Fixed code
def get_module(name):
    """
    Return module or None. Absolute import is required.

    :param (str) name: Dot-separated module path. E.g., 'scipy.stats'.
    :raise: (ImportError) Only when exc_msg is defined.
    :return: (module|None) If import succeeds, the module will be returned.

    """
    if name not in _not_importable:
        try:
            return import_module(name)
        except ImportError:
            _not_importable.add(name)
        except Exception as e:
            _not_importable.add(name)
            msg = "Error importing optional module {}".format(name)
            logger.exception(msg)