Skip to content

Commit

Permalink
Handle AnonymousUser in request
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhai committed Oct 24, 2024
1 parent 93805e0 commit c5074a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion llmstack/events/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class JSONEncoder(json.JSONEncoder):
def default(self, o):
from django.contrib.auth.models import User
from django.contrib.auth.models import AnonymousUser, User

if isinstance(o, uuid.UUID):
return str(o)
Expand All @@ -27,6 +27,8 @@ def default(self, o):
return o.decode("utf-8")
elif isinstance(o, BaseModel):
return o.model_dump()
elif isinstance(o, AnonymousUser):
return "AnonymousUser"

return super().default(o)

Expand Down
2 changes: 1 addition & 1 deletion llmstack/server/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def connect(self):
location = get_location(request_ip)
request_location = f"{location.get('city', '')}, {location.get('country_code', '')}" if location else ""

request_user_email = self._user.email if self._user else None
request_user_email = self._user.email if self._user and not self._user.is_anonymous else None

self._source = WebAppRunnerSource(
id=self._session_id,
Expand Down

0 comments on commit c5074a3

Please sign in to comment.