Duplicate detection improved but refactoring necessary to make the whole thing more managable
This commit is contained in:
@@ -273,10 +273,28 @@ async def process_wix_form_submission(
|
||||
reservation, db_customer.id
|
||||
)
|
||||
except IntegrityError as e:
|
||||
_LOGGER.exception("Database integrity error creating reservation: %s", e)
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Database error creating reservation"
|
||||
) from e
|
||||
await db_session.rollback()
|
||||
# Check if this is a duplicate (unique constraint violation)
|
||||
error_msg = str(e.orig) if hasattr(e, 'orig') else str(e)
|
||||
is_duplicate = any(keyword in error_msg.lower() for keyword in ['unique', 'duplicate', 'already exists'])
|
||||
|
||||
if is_duplicate:
|
||||
_LOGGER.info(
|
||||
"Duplicate reservation detected for unique_id=%s, skipping (this is expected for reprocessing)",
|
||||
unique_id
|
||||
)
|
||||
return {
|
||||
"status": "duplicate",
|
||||
"message": "Reservation already exists (duplicate submission)",
|
||||
"unique_id": unique_id,
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
else:
|
||||
# Real integrity error (not a duplicate)
|
||||
_LOGGER.exception("Database integrity error creating reservation: %s", e)
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Database error creating reservation"
|
||||
) from e
|
||||
|
||||
async def push_event():
|
||||
# Fire event for listeners (push, etc.) - hotel-specific dispatch
|
||||
@@ -581,9 +599,33 @@ async def process_generic_webhook_submission(
|
||||
|
||||
# Use ReservationService to create reservation
|
||||
reservation_service = ReservationService(db_session)
|
||||
db_reservation = await reservation_service.create_reservation(
|
||||
reservation, db_customer.id
|
||||
)
|
||||
try:
|
||||
db_reservation = await reservation_service.create_reservation(
|
||||
reservation, db_customer.id
|
||||
)
|
||||
except IntegrityError as e:
|
||||
await db_session.rollback()
|
||||
# Check if this is a duplicate (unique constraint violation)
|
||||
error_msg = str(e.orig) if hasattr(e, 'orig') else str(e)
|
||||
is_duplicate = any(keyword in error_msg.lower() for keyword in ['unique', 'duplicate', 'already exists'])
|
||||
|
||||
if is_duplicate:
|
||||
_LOGGER.info(
|
||||
"Duplicate reservation detected for unique_id=%s, skipping (this is expected for reprocessing)",
|
||||
unique_id
|
||||
)
|
||||
return {
|
||||
"status": "duplicate",
|
||||
"message": "Reservation already exists (duplicate submission)",
|
||||
"unique_id": unique_id,
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
else:
|
||||
# Real integrity error (not a duplicate)
|
||||
_LOGGER.exception("Database integrity error creating reservation: %s", e)
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Database error creating reservation"
|
||||
) from e
|
||||
|
||||
async def push_event():
|
||||
# Fire event for listeners (push, etc.) - hotel-specific dispatch
|
||||
|
||||
Reference in New Issue
Block a user