Sep 16 - Optimize code, part 1, fix Internal Server error

This commit is contained in:
2026-09-16 13:38:10 -04:00
parent 7626287344
commit 2c5627354e
2 changed files with 65 additions and 8 deletions
+14
View File
@@ -858,6 +858,14 @@ logger_handler.logger.info("...")
logger_handler.logger.error("...", exc_info=True) # always pass exc_info=True in except blocks
```
**`logger_handler` is a proxy object, not the `AppLogger`** (`extensions.py`, Set 24). Modules
imported before `create_app()` runs `init_logger()``utils/helpers.py`, `utils/template_helpers.py`,
`utils/geocoding.py` — copy this reference at import time. It used to be a plain `None`, so any
logging call from those modules raised `AttributeError: 'NoneType' object has no attribute 'logger'`.
The proxy forwards to the real `AppLogger` once `init_logger()` builds it, and to a stdlib logger
before that. **Do not restore `logger_handler = None`**, and do not test it for `None`/truthiness —
it is always truthy.
### Log Destinations
- `logs/application.log` — rotating 10MB/5 backups
- `logs/errors.log` — rotating 5MB/10 backups
@@ -1319,6 +1327,12 @@ it (the workers share no pub/sub).
| — | Verified offline (67 checks): formula guard incl. openpyxl save/reload, role gates per role and for JSON callers, limiter behind ProxyFix (spoofed XFF, shared IP, per-username cap, reset on login), debug endpoint, check-in ID rule, config limits, POST-only routes, migration against a fake cursor (create / covered / re-run / fallback / missing column). Not run against MySQL, Nginx or a browser |
| — | Known, not changed: `templates/confirm_delete_qr.html` links (GET) to the POST-only `deactivate_qr_code`, so that button returns 405 |
### Set 24 — Access-Denied Path Raised 500 (logger_handler was None) (Sept 16, 2026)
| File | Fix |
|---|---|
| `extensions.py` | `logger_handler` is now a proxy (see §14). `utils/helpers.py` imports it at module import time, which happens BEFORE `init_logger()`, so it was permanently `None`: the Set 23 role check logged a warning when denying access and raised `AttributeError: 'NoneType' object has no attribute 'logger'` → 500 for a project manager opening `/time-attendance` or editing a QR code. The same latent bug affected `generate_qr_code()` logging in `utils/helpers.py` and every call in `utils/template_helpers.py` / `utils/geocoding.py` |
| — | The step-1 tests had stubbed a working logger into `extensions`, which hid it. They now import the real module and run the role checks BEFORE `init_logger()`, exactly like a gunicorn worker |
---
## 21. Infrastructure & Deployment