Problem
The Favorite model allows duplicate rows for the same (user_id, entry_id, campaign_id) combination at the database level. There is no unique constraint preventing this.
The application-level fix in #540 prevents the cross-campaign collision, but a DB-level unique constraint on (user_id, entry_id, campaign_id) would make this robust against any future code paths that bypass the DAO.
Suggested Fix
Add a UniqueConstraint to the Favorite model:
__table_args__ = (
UniqueConstraint("user_id", "entry_id", "campaign_id", name="uq_favorite_user_entry_campaign"),
)
And a corresponding Alembic migration.
Related
Problem
The
Favoritemodel allows duplicate rows for the same(user_id, entry_id, campaign_id)combination at the database level. There is no unique constraint preventing this.The application-level fix in #540 prevents the cross-campaign collision, but a DB-level unique constraint on
(user_id, entry_id, campaign_id)would make this robust against any future code paths that bypass the DAO.Suggested Fix
Add a
UniqueConstraintto theFavoritemodel:And a corresponding Alembic migration.
Related