Skip to content

API: Favorite.campaign_id not enforced at DB level -- missing unique constraint #541

@ayushshukla1807

Description

@ayushshukla1807

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions