Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/eventyay/base/services/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ def _create_room(data, with_channel=False, permission_preset="public", creator=N
channel = None
if with_channel:
channel = Channel.objects.create(event_id=room.event_id, room=room)
# Pre-warm the channel relationship to avoid lazy-loading issues during serialization
room.channel = channel

AuditLog.objects.create(
event_id=room.event_id,
Expand Down Expand Up @@ -360,6 +362,8 @@ async def create_room(event, data, creator):

async def get_room_config_for_user(room: str, event_id: str, user):
room = await get_room(id=room, event_id=event_id)
if room is None:
Comment on lines 363 to +365
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: get_room_config_for_user now returns None in some cases; consider tightening type hints and callers to reflect the optional return.

Since the function can now return None, its return type should be updated to Optional[...], and all callers should be checked (beyond push_room_info and push_schedule_data) to ensure they correctly handle the None case. Making this optionality explicit in the signature reduces the risk of future callers assuming a non-None config.

Suggested implementation:

from typing import Optional  # if there's already a typing import, extend it instead of adding a new line


async def get_room_config_for_user(room: str, event_id: str, user) -> Optional[dict]:
    room = await get_room(id=room, event_id=event_id)
    if room is None:
        return None

    permissions = await database_sync_to_async(room.event.get_all_permissions)(user)
    return get_room_config(room, permissions[room] | permissions[room.event])
  1. If event.py already has a from typing import ... line, extend it instead of adding a second import, e.g.:
    • from typing import Any, Dict, Optional
  2. Replace dict in the return type with the concrete type used by get_room_config if it already has a more precise annotation, for example:
    • -> Optional[RoomConfig]
    • or -> Optional[Dict[str, Any]]
  3. Update all call sites of get_room_config_for_user (beyond push_room_info and push_schedule_data) to handle the None case explicitly, for example:
    • Early-return if the config is None.
    • Or branch logic to only use the config when it is non-None.
  4. If you use a static type checker (e.g. mypy), run it to confirm all callers now respect the Optional[...] return type.

return None
permissions = await database_sync_to_async(room.event.get_all_permissions)(user)
return get_room_config(room, permissions[room] | permissions[room.event])

Expand Down
6 changes: 6 additions & 0 deletions app/eventyay/features/live/modules/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ async def push_room_info(self, body):
conf = await get_room_config_for_user(
body["room"], self.consumer.event.id, self.consumer.user
)
if conf is None:
# Room not found or not yet available, skip broadcasting
return
if "room:view" not in conf["permissions"]:
return
await self.consumer.send_json(
Expand Down Expand Up @@ -434,6 +437,9 @@ async def push_schedule_data(self, body):
config = await get_room_config_for_user(
body["room"], self.consumer.event.id, self.consumer.user
)
if config is None:
# Room not found or not yet available, skip broadcasting
return
if "room:view" not in config["permissions"]:
return
await self.consumer.send_json(
Expand Down