Skip to content

Commit

Permalink
fix: terminate early if adding duplicate event
Browse files Browse the repository at this point in the history
  • Loading branch information
seelengxd committed Sep 24, 2024
1 parent ff637f7 commit 9995a4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions backend/src/events/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/scripts/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def test_associations():
# session.delete(original_article)


# test_associations()
test_associations()

0 comments on commit 9995a4c

Please sign in to comment.