Skip to content
Open
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
22 changes: 22 additions & 0 deletions buzz/ticketing/doctype/event_booking/event_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import get_datetime, get_datetime_in_timezone, now_datetime

from buzz.payments import mark_payment_as_received

Expand Down Expand Up @@ -37,6 +38,7 @@ class EventBooking(Document):
# end: auto-generated types

def validate(self):
self.validate_event_has_ended()
self.validate_ticket_availability()
self.fetch_amounts_from_ticket_types()
self.set_currency()
Expand Down Expand Up @@ -173,3 +175,23 @@ def cancel_all_tickets(self):
tickets = frappe.db.get_all("Event Ticket", filters={"booking": self.name}, pluck="name")
for ticket in tickets:
frappe.get_cached_doc("Event Ticket", ticket).cancel()

def validate_event_has_ended(self):
event_doc = frappe.get_cached_doc("Buzz Event", self.event)

if not event_doc.end_date:
return

time_part = str(event_doc.end_time) if event_doc.end_time else "23:59:59"
event_end_naive = get_datetime(f"{event_doc.end_date} {time_part}")

if event_doc.time_zone:
current_time_aware = get_datetime_in_timezone(event_doc.time_zone)
current_time_at_venue = current_time_aware.replace(tzinfo=None)

if current_time_at_venue > event_end_naive:
frappe.throw(_("Cannot book tickets. This event has already ended."), title=_("Event Ended"))

else:
if now_datetime() > event_end_naive:
frappe.throw(_("Cannot book tickets. This event has already ended."), title=_("Event Ended"))
Comment on lines +195 to +197
Copy link

@coderabbitai coderabbitai bot Jan 6, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix TypeError: comparing timezone-aware and naive datetimes.

The else branch at line 196 compares now_datetime() (which returns a timezone-aware datetime in the system timezone) with event_end_naive (which is naive). Python raises TypeError when comparing timezone-aware and naive datetimes.

To fix this, make now_datetime() naive before comparison by stripping its timezone info, similar to the approach in the if branch.

🔎 Proposed fix to use naive datetime comparison
 	else:
-		if now_datetime() > event_end_naive:
+		if now_datetime().replace(tzinfo=None) > event_end_naive:
 			frappe.throw(_("Cannot book tickets. This event has already ended."), title=_("Event Ended"))
🤖 Prompt for AI Agents
In @buzz/ticketing/doctype/event_booking/event_booking.py around lines 195 -
197, The comparison in the else branch uses now_datetime() (timezone-aware)
against event_end_naive (naive), causing a TypeError; convert now_datetime() to
a naive datetime before comparing (e.g., strip tzinfo as done in the if branch)
so that the comparison between now and event_end_naive is between two naive
datetimes; update the else block where now_datetime() is compared to
event_end_naive and ensure you reuse the same naive conversion helper or logic
used earlier to keep behavior consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

@imgullu786 Can you confirm if this is not the case?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!