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

IndexError: string index out of range #4724

Open
sentry-io bot opened this issue Nov 5, 2024 · 3 comments
Open

IndexError: string index out of range #4724

sentry-io bot opened this issue Nov 5, 2024 · 3 comments
Labels
bug Something isn't working deck-scrubbing Tech debt or other between-initiative tidy-up work

Comments

@sentry-io
Copy link

sentry-io bot commented Nov 5, 2024

Sentry Issue: JOB-SERVER-MF

TypeError: 'User' object is not subscriptable
  File "django/template/base.py", line 883, in _resolve_lookup
    current = current[bit]
  File "django/utils/functional.py", line 253, in inner
    return func(_wrapped, *args)

IndexError: string index out of range
(24 additional frame(s) were not displayed)
...
  File "jobserver/models/user.py", line 218, in initials
    return "".join(w[0].upper() for w in self.name.split(" "))
  File "jobserver/models/user.py", line 218, in <genexpr>
    return "".join(w[0].upper() for w in self.name.split(" "))
@Jongmassey
Copy link
Contributor

Jongmassey commented Nov 5, 2024

This appears to be based in the initials generation code which is used in place of GitHub avatars (slack thread ) which fails with @Mary-Anya 's mononymic user account trailing space in username (see below)

@Jongmassey
Copy link
Contributor

Jongmassey commented Nov 5, 2024

>>> failures = []
>>> for u in User.objects.all():
...   try:
...     i = u.initials
...   except:
...     failures.append(u)
... 
>>> failures
[<User: Mary >]

also

select * from jobserver_user u where fullname like '% ' or username like '% '

just returns Mary's user

I think it's because Mary's fullname has a trailing space

@lucyb lucyb added bug Something isn't working deck-scrubbing Tech debt or other between-initiative tidy-up work labels Nov 6, 2024
@mikerkelly
Copy link
Contributor

mikerkelly commented Nov 6, 2024

If I go to http://localhost:8000/settings/ and enter some trailing spaces in my fullname they seemingly get scrubbed on form save. And the same at http://localhost:8000/staff/users/mikerkelly/.

So probably it is only the social auth initial population we need to worry about.

User.fullname has a comment saying this is initially populated by social auth. Probably we could address the issue by overriding User.save or with a pre_save signal to strip whitespace from that field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deck-scrubbing Tech debt or other between-initiative tidy-up work
Projects
None yet
Development

No branches or pull requests

3 participants