Home Features Docs Blog Philosophy Examples FAQ Live Demo Hosting
DJE-014ErrorConfiguration

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.

authbug-fixedconfigpresence

Affected versions: <0.3.0

Solution

Recommended

Upgrade to djust >= 0.3.0

The PresenceMixin now checks for hasattr(request, 'user') before accessing request.user, gracefully handling unauthenticated contexts.

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")