-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
adminFeatures needed for the Admin UI (people running the site)Features needed for the Admin UI (people running the site)
Description
For admin routes, we're often a little less guarded, and can lead to 5xx errors in production.
An improvement could be to have a factory pattern on the routes, which pre-hydrates the object from the DB before entering the view, like we do for Users:
warehouse/warehouse/admin/routes.py
Lines 114 to 120 in 5845055
| config.add_route( | |
| "admin.user.detail", | |
| "/admin/users/{username}/", | |
| domain=warehouse, | |
| factory="warehouse.accounts.models:UserFactory", | |
| traverse="/{username}", | |
| ) |
warehouse/warehouse/accounts/models.py
Lines 52 to 60 in 837de24
| class UserFactory: | |
| def __init__(self, request): | |
| self.request = request | |
| def __getitem__(self, username): | |
| try: | |
| return self.request.db.query(User).filter(User.username == username).one() | |
| except NoResultFound: | |
| raise KeyError from None |
Originally posted by @miketheman in #19695 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
adminFeatures needed for the Admin UI (people running the site)Features needed for the Admin UI (people running the site)