From 9995a4cb87b5c50d0741a0e7a3cc22ce46170d02 Mon Sep 17 00:00:00 2001 From: seeleng Date: Tue, 24 Sep 2024 21:46:18 +0800 Subject: [PATCH] fix: terminate early if adding duplicate event --- backend/src/events/process.py | 14 ++++++++++++++ backend/src/scripts/seed.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/src/events/process.py b/backend/src/events/process.py index 3c957b03..227b4743 100644 --- a/backend/src/events/process.py +++ b/backend/src/events/process.py @@ -37,6 +37,20 @@ def add_event_to_db(event: EventLLM) -> bool: categories = get_categories() with Session(engine) as session: + # Check for duplicates + eventORM = session.scalars( + select(Event).where( + Event.title == event.title, + Event.description == Event.description, + Event.duplicate == event.duplicate, + Event.is_singapore == event.is_singapore, + Event.original_article_id == event.original_article_id, + ) + ).first() + if eventORM: + print("duplicate detected:", event) + return False + try: article = session.get(Article, event.original_article_id) if not article: diff --git a/backend/src/scripts/seed.py b/backend/src/scripts/seed.py index ee76df83..387b6da2 100644 --- a/backend/src/scripts/seed.py +++ b/backend/src/scripts/seed.py @@ -97,4 +97,4 @@ def test_associations(): # session.delete(original_article) -# test_associations() +test_associations()