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

Upgrading to Django 4.0 gives me "AttributeError: 'SafeString' object has no attribute 'get_bundle'" #319

Closed
pwhipp opened this issue May 29, 2022 · 2 comments

Comments

@pwhipp
Copy link

pwhipp commented May 29, 2022

I've upgraded the venv from python 3.9.2/django 3.0.2 to Python 3.10.4/django 4.0.4 - django-webpack-loader is 1.5.0

ERROR 2022-05-29 15:06:12,756 log 186271 140206875318016 Internal Server Error: /
Traceback (most recent call last):
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 472, in thread_handler
    raise exc_info[1]
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 284, in _get_response_async
    response = await sync_to_async(
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler
    return func(*args, **kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/backends/django.py", line 62, in render
    return self.template.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/library.py", line 239, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/src/front_end/templatetags/front_end.py", line 16, in render_bundle
    tags = get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs)
  File "/home/paul/wk/cliosoft/sosmgrweb/src/front_end/templatetags/front_end.py", line 21, in get_as_tags
    bundle = _get_bundle(bundle_name, extension, config)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/utils.py", line 39, in _get_bundle
    bundle = loader.get_bundle(bundle_name)
AttributeError: 'SafeString' object has no attribute 'get_bundle'

The template is unchanged:

{% load static core %}
{% load render_bundle from front_end %}
<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ site_name }}</title>
    <link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
    <link href="{% static 'bootstrap-3.3.6-dist/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/style.css' %}" rel="stylesheet">
    <link href="{% static 'font-awesome-new/css/fontawesome-all.css' %}"  rel="stylesheet">
    <link href="{% static 'font-awesome-new/css/fa-solid.css' %}"  rel="stylesheet">
    <link href="{% static 'font-awesome-new/css/fa-light.css' %}"  rel="stylesheet">
    <link href="{% static 'font-awesome-new/css/fa-regular.css' %}"  rel="stylesheet">
    <link href="{% static 'select2/css/select2.min.css' %}"  rel="stylesheet">
    <link href="{% static 'css/codemirror.css' %}"  rel="stylesheet">
    <link href="{% static 'css/core.css' %}"  rel="stylesheet">
    <link href="{% static 'css/react-select.css' %}"  rel="stylesheet">
    <link href="{% static 'css/sosadmin.css' %}"  rel="stylesheet">
    <link href="{% static 'Roboto-fonts/stylesheet.css' %}"  rel="stylesheet">
    <script>
      window.configuration = {{ configuration|js }};
      window.initial_view_states = {{ initial_view_states|js }};
    </script>
</head>

<body class="sos-body">
<div id="main" ></div>
{% render_bundle 'main' %}
</body>
</html>

I can't find anything online about this.

@pwhipp
Copy link
Author

pwhipp commented May 30, 2022

The _get_bundle protocol has changed (which is fair enough as it is 'internal/private' in spite of my having needed it).
To explore further I switched to the default webpack_loader template tags but this also gives an error:

ERROR 2022-05-29 17:23:14,663 log 197319 140566912517888 Internal Server Error: /
Traceback (most recent call last):
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 472, in thread_handler
    raise exc_info[1]
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 284, in _get_response_async
    response = await sync_to_async(
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler
    return func(*args, **kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/backends/django.py", line 62, in render
    return self.template.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/django/template/library.py", line 239, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/templatetags/webpack_loader.py", line 20, in render_bundle
    tags = utils.get_as_tags(
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/utils.py", line 63, in get_as_tags
    bundle = _get_bundle(loader, bundle_name, extension)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/utils.py", line 39, in _get_bundle
    bundle = loader.get_bundle(bundle_name)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/loader.py", line 116, in get_bundle
    filtered_chunks = self.filter_chunks(chunks)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/loader.py", line 58, in filter_chunks
    ignore = any(regex.match(chunk)
  File "/home/paul/wk/cliosoft/sosmgrweb/venv/lib/python3.10/site-packages/webpack_loader/loader.py", line 58, in <genexpr>
    ignore = any(regex.match(chunk)
TypeError: expected string or bytes-like object

It looks like the "chunks" in the webpack-stats file generated by the bundle tracker are no longer appropriate.

To solve this I had to upgrade the webpack npm packages to the latest versions too and then do a build in order to run the tracker and generate updated stats for use by the django python files.

@pwhipp pwhipp closed this as completed May 30, 2022
@fjsj
Copy link
Member

fjsj commented May 30, 2022

Thanks, always update together the webpack-bundle-tracker and django-webpack-loader. If the version number is the same in both, they will be compatible.

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

No branches or pull requests

2 participants