DJE-014
Error
Configuration
PresenceMixin crash without AuthenticationMiddleware
Error message
AttributeError: 'WSGIRequest' object has no attribute 'user'
The PresenceMixin's track_presence() method accessed request.user without first checking if the user attribute exists. Applications that do not use AuthenticationMiddleware (e.g., public kiosks, embedded widgets) would crash when the presence feature was used.
auth
bug-fixed
config
presence
Affected versions: <0.3.0
Solution
Before (problematic)
class PresenceMixin:
def track_presence(self, request):
user = request.user # Crashes without auth middleware!
self.register_presence(user.username)
After (fixed)
class PresenceMixin:
def track_presence(self, request):
if hasattr(request, "user") and request.user.is_authenticated:
self.register_presence(request.user.username)
else:
self.register_presence("anonymous")