Handle if user subscription field doesn't exists in telemetry func

Avoid null ref in the method when running Khoj server in anon mode
This commit is contained in:
Debanjum Singh Solanky 2023-11-28 14:12:20 -08:00
parent 110d7646fc
commit 643e018947

View file

@ -72,7 +72,7 @@ def update_telemetry_state(
metadata: Optional[dict] = None, metadata: Optional[dict] = None,
): ):
user: KhojUser = request.user.object if request.user.is_authenticated else None user: KhojUser = request.user.object if request.user.is_authenticated else None
subscription: Subscription = user.subscription if user and user.subscription else None subscription: Subscription = user.subscription if user and hasattr(user, "subscription") else None
user_state = { user_state = {
"client_host": request.client.host if request.client else None, "client_host": request.client.host if request.client else None,
"user_agent": user_agent or "unknown", "user_agent": user_agent or "unknown",