Skip to content

Conversation

@MohammedAnasNathani
Copy link
Contributor

@MohammedAnasNathani MohammedAnasNathani commented Nov 29, 2025

Description

Fixed a "Fatal Server Error" that occurred when creating a new room with a chat channel (e.g., "Chat" or "BigBlueButton" modules enabled).

The issue was caused because RoomConfigSerializer attempted to access the room.channel relationship inside the AuditLog creation step. Since the channel object was created but not manually attached to the room instance in memory, the serializer triggered a lazy database lookup inside the sync_to_async context, which likely failed or caused a race condition.

Issues

Closes #1343

Fix

  • Explicitly attached the newly created channel object to room.channel in memory before calling the serializer.
  • This ensures RoomConfigSerializer(room).data can serialize the channel ID without triggering additional database queries or failing.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by Sourcery

Bug Fixes:

  • Attach the newly created channel to the in-memory room instance so room configuration serialization during audit logging no longer triggers problematic lazy database access.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 29, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures that when creating a room with an associated chat channel, the newly created Channel instance is attached to the in-memory Room object before audit logging/serialization, preventing lazy-loading-related fatal errors.

Sequence diagram for room creation with attached channel

sequenceDiagram
    participant Caller
    participant Service as EventService
    participant Room
    participant ChannelModel as Channel
    participant Serializer as RoomConfigSerializer
    participant AuditLogModel as AuditLog

    Caller->>Service: _create_room(data, with_channel=True, permission_preset, creator)
    Service->>Room: create Room instance
    activate Room
    Room-->>Service: room
    deactivate Room

    alt with_channel is True
        Service->>ChannelModel: objects.create(event_id=room.event_id, room=room)
        activate ChannelModel
        ChannelModel-->>Service: channel
        deactivate ChannelModel

        Service->>Room: set channel on room (room.channel = channel)
    end

    Service->>Serializer: RoomConfigSerializer(room)
    activate Serializer
    Serializer-->>Service: serialized room data (includes channel id)
    deactivate Serializer

    Service->>AuditLogModel: objects.create(event_id=room.event_id, data=serialized room data)
    activate AuditLogModel
    AuditLogModel-->>Service: audit_log
    deactivate AuditLogModel

    Service-->>Caller: room
Loading

Class diagram for Room, Channel, AuditLog and RoomConfigSerializer

classDiagram
    class Room {
        int id
        int event_id
        Channel channel
    }

    class Channel {
        int id
        int event_id
        Room room
    }

    class AuditLog {
        int id
        int event_id
        string data
        datetime created_at
    }

    class RoomConfigSerializer {
        Room instance
        dict data
        RoomConfigSerializer(Room instance)
    }

    Room --> Channel : has_one
    Channel --> Room : belongs_to
    AuditLog --> Room : logs_changes_for
    RoomConfigSerializer --> Room : serializes
    RoomConfigSerializer ..> Channel : accesses_channel_via_room
Loading

File-Level Changes

Change Details Files
Attach newly created channel instance to the in-memory room object to avoid lazy DB lookup during serialization/audit logging.
  • After creating a Channel when with_channel is True, assign the created channel instance to the room.channel attribute before any serialization or audit logging occurs
app/eventyay/base/services/event.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1343 Fix the backend bug causing a "Fatal Server Error" when creating a room in the video component so that room creation succeeds.
#1343 Ensure that after attempting to create a room in the video component, the system no longer gets stuck in a continuous loading state (i.e., the request completes successfully).

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mariobehling mariobehling requested a review from Copilot November 30, 2025 05:31
Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

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

Please showcase functionality by providing screenshots.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a fatal server error that occurred when creating a room with a chat channel enabled. The issue was caused by Django's ORM lazy-loading behavior when accessing the room.channel relationship during audit log serialization within an async context.

Key Changes:

  • Explicitly assigns the newly created channel object to room.channel in memory after channel creation
  • Ensures RoomConfigSerializer can access the channel without triggering additional database queries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MohammedAnasNathani
Copy link
Contributor Author

@mariobehling Thanks for the review.

  • Whitespace: I have fixed the trailing whitespace issue flagged by Copilot.
  • Screenshot Request: Regarding the UI showcase: This PR addresses a Backend 500 Server Error (Crash) during the database transaction phase of room creation.

Since I am working in a cloud-based environment (Codespaces), I am currently blocked by a WebSocket restriction (Error 1006) which prevents the video frontend from rendering fully to capture a screenshot.
However, the fix is verified via code logic:

  • Bug: The RoomConfigSerializer was triggering a RelatedObjectDoesNotExist error by trying to lazy-load room.channel inside an async transaction block.
  • Fix: I explicitly pre-warm the room.channel relationship in memory (room.channel = channel) immediately after creation. This prevents the serializer from hitting the database again, resolving the crash.
    The logic ensures the transaction completes successfully instead of rolling back. I hope this technical verification suffices given the environment constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Bug (Video): Unable to Create Rooms in Video Component – All Attempts Return “Fatal Server Error”

2 participants