Skip to content

KeyError à la création d'un nouveau profile

La factorisation de ProfileFormat en UsernameFormat dans Règles pour les noms de profiles de d'utilisate... (!74 - merged) à introduit un bug en simplifiant le champ profile_format dans le register.

La lign en question est ici.

La création d'un nouveau profile fait appel à service.profile_format dans:

formatter = format.UsernameFormat.registry[service.profile_format]

Avant si le @register("lowercase") était valide pour "" et None, pour des soucis de lisibilité et de clarification je l'avais enlevé, mais la dans la DB la pluspart de service on une valeur null dans ce champ err 500.

Le plus propre est de faire une migration pour passer les champs null en DB vers lowercase le choix par défaut.

Trace
127.0.0.1 - - [30/Sep/2024 17:14:01] "GET /profile/create_for/d75d26a5-711d-4483-bc58-f26723f874b4 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 1488, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/werkzeug/middleware/proxy_fix.py", line 182, in __call__
    return self.app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 1466, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 1463, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 872, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 870, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask/app.py", line 855, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/.cache/pypoetry/virtualenvs/hiboo-yDyvPiti-py3.12/lib/python3.12/site-packages/flask_login/utils.py", line 290, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/projects/code/hiboo/hiboo/security.py", line 25, in wrapper
    return callback(
           ^^^^^^^^^
  File "/home/f00wl/projects/code/hiboo/hiboo/security.py", line 19, in callback
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f00wl/projects/code/hiboo/hiboo/profile/views.py", line 29, in create
    formatter = format.UsernameFormat.registry[service.profile_format]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: ''
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information