GhostManager / Ghostwriter

The SpecterOps project management and reporting engine

Home Page:https://ghostwriter.wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[v4.0.6] Error after login

ArgentEnergy opened this issue · comments

ERROR 2024-01-30 18:50:52,792 log 24 140438908595000 Internal Server Error: /home/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 38, in inner
    response = await get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
    response = await wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
  File "/usr/local/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/app/ghostwriter/api/utils.py", line 478, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/app/ghostwriter/home/views.py", line 125, in get
    return render(request, "index.html", context=context)
  File "/usr/local/lib/python3.10/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/usr/local/lib/python3.10/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/usr/local/lib/python3.10/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/defaulttags.py", line 315, in render
    return nodelist.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.10/site-packages/django/template/defaulttags.py", line 449, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "/usr/local/lib/python3.10/site-packages/django/urls/base.py", line 86, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/urls/resolvers.py", line 698, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'avatar_download' with keyword arguments '{'slug': 'colin'}' not found. 1 pattern(s) tried: ['users/(?P<slug>[-a-zA-Z0-9_]+)/avatar\\Z']

Running into this issue with the latest version. After logging in, application is unusable because 500 error is thrown.

Hey @ArgentEnergy, the error is related to a change in how your user profile picture loads. If the user colin does not have a user profile somehow or the username does not exist, the route should return a 404 and the default avatar.

You're seeing a 500 error because the server thinks the avatar_download URI does not match any known routes.

Are you able to directly visit https:///users/colin or https:///users/colin/avatar?

Is colin a new user you just created? How did you create it? Also, is this a preexisting Ghostwriter instance or a new install?

If I can follow in your steps and reproduce it, that will make it easier to figure out the cause. Your ghostwriter.users.urls.py file should look like this with v4.0.6. The last route is what isn't getting found:

app_name = "users"
urlpatterns = [
    path("~redirect/", view=user_redirect_view, name="redirect"),
    path("<str:username>/", user_detail_view, name="user_detail"),
    path("<str:username>/update/", user_update_view, name="user_update"),
    path("<str:username>/update/avatar/", view=userprofile_update_view, name="userprofile_update"),
    path(
        "<slug:slug>/avatar",
        avatar_download,
        name="avatar_download",
    ),
]

This is a pre-existing GW installation where the user account was already there. Updated from 4.0.2 to 4.0.6. It seems any non-admin page I visit throws that 500 error.

I was able to get into /admin as this is an admin user. Usernames are firstname.lastname convention but never had a problem with that in past versions.

The user also didn't have an avatar set.

The ghostwriter.users.urls.py file is the same that you wrote down.

@chrismaddalena The root cause of this is due to the regular expression missing a period.

['users/(?P<slug>[-a-zA-Z0-9_]+)/avatar\\Z']

I removed the period between my firstname and lastname in the username and it worked. Not sure where in the code this regular expression is to add a . character.

There is also a bug in the admin application when clicking the Clear avatar checkbox and clicking save.

ERROR 2024-01-31 14:10:24,245 log 23 140011339942712 Internal Server Error: /admin/users/user/2/change/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 38, in inner
    response = await get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
    response = await wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
  File "/usr/local/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1660, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1587, in _changeform_view
    self.save_related(request, form, formsets, not add)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1127, in save_related
    self.save_formset(request, form, formset, change=change)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1115, in save_formset
    formset.save()
  File "/usr/local/lib/python3.10/site-packages/django/forms/models.py", line 681, in save
    return self.save_existing_objects(commit) + self.save_new_objects(commit)
  File "/usr/local/lib/python3.10/site-packages/django/forms/models.py", line 805, in save_existing_objects
    saved_instances.append(self.save_existing(form, obj, commit=commit))
  File "/usr/local/lib/python3.10/site-packages/django/forms/models.py", line 662, in save_existing
    return form.save(commit=commit)
  File "/usr/local/lib/python3.10/site-packages/django/forms/models.py", line 468, in save
    self.instance.save()
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 787, in save_base
    post_save.send(
  File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 180, in send
    return [
  File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/app/ghostwriter/home/signals.py", line 45, in delete_old_avatar_on_update
    if instance._current_avatar.path not in instance.avatar.path:
  File "/usr/local/lib/python3.10/site-packages/django/db/models/fields/files.py", line 58, in path
    self._require_file()
  File "/usr/local/lib/python3.10/site-packages/django/db/models/fields/files.py", line 40, in _require_file
    raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'avatar' attribute has no file associated with it.

I originally didn't have an avatar and added one last night to try and see if that would fix the first error mentioned here.

Figured out the fix for the first issue.

path(
        "<str:slug>/avatar",
        avatar_download,
        name="avatar_download",
    ),

Have to replace slug: with str: to allow periods in usernames.

Ah, a period in the username makes sense. Thanks for following up on that! We'll push a fix for this today.