0.5.3 - Bug fixes, security hardening, test infra improvements, and code cleanup
Fixed
- Test auth header mismatch —
test_login_view.pyused"Token"prefix but KnoxAUTH_HEADER_PREFIXis"Bearer". Test was returning 401 instead of 200. - Test logging crash —
test_settings.pycleared console handler filters, but JSON formatter expected fields injected byRequestIDFilter. Mock filter now provides dummy values for all fields. - Unhandled CORS env var —
env.list("CORS_ALLOWED_ORIGINS")had no default, crashing startup whenDEBUG=Falseand env var missing. - Sentry startup crash —
sentry_sdk.init()requiredSENTRY_DSNin non-DEBUG mode. Now gated on env var existence with graceful fallback. - Sentry 100% sampling — Both
traces_sample_rateandprofiles_sample_ratereduced to0.1in production to avoid quota exhaustion. - Password validation bypass —
UserProfileSerializer.validate()passed blank model instance tovalidate_password()instead ofself.instance, lettingUserAttributeSimilarityValidatormiss email/name comparisons. - Email field writable —
emailfield allowed modification via PUT/PATCH without verification. Made read-only inUserProfileSerializer. - Missing HSTS headers — Added
SECURE_HSTS_SECONDS,SECURE_SSL_REDIRECT, andSECURE_PROXY_SSL_HEADERwhenDEBUG=False. - Wrong middleware ordering in tests — Mock
RequestIDMiddlewareinserted afterCommonMiddlewareinstead of position 0, causing behavior mismatch with production. - Seed command error swallowing —
except Exceptioncaught everything with misleading "already exists" message. Narrowed toIntegrityError. Removed@transaction.atomicfrom outer handler; per-user savepoints prevent total rollback on individual failures. - Shared Redis throttle state — Test throttles persisted across runs via shared Redis cache. Switched tests to
LocMemCacheto isolate throttle state. - Test throttles incomplete — Only
user_loginthrottle was relaxed in tests;userandanonrates now also set to1000/minute.
Removed
ADMIN_MEDIA_PREFIX(dead config, removed in Django 2.0)USER_AGENTS_CACHE(orphan setting,django-user-agentsnot installed)from __future__ import absolute_import, unicode_literalsfromconf/__init__.pyandconf/celery.py(Python 2 compat, dead code)django.template.defaultfiltersfrom templatebuiltins(all default filters already available)- Dead
get_serializer_context()override inLoginView(DRF already injectsrequest) - Redundant
KeyErrorfromBaseTaskWithRetry.autoretry_for(subclass ofException) scripts/celery.py(dead code, never referenced)- Stale
.pycfiles inscripts/__pycache__/(orphaned from deleteddjango.py)
Changed
CustomUserManager.create_user()now usesuser.save(using=self._db)for multi-DB safetyRequestIDMiddlewareusesrequest.user.pkinstead ofrequest.user.idas canonical identifier- ruff
target-versionand mypypython_versionupdated frompy313topy314(matches runtime) pytest.ininow includesaddopts = --reuse-db --nomigrationsfor faster test setup
Full Changelog: 0.5.2...0.5.3