Skip to content

SourceStar is queried via one_or_none() without a uniqueness constraint #7834

@cfm

Description

@cfm

The Source model assumes that its star attribute will return either zero or one SourceStar instance:

star = relationship("SourceStar", uselist=False, backref="source")

But SourceStar.source_id has no uniqueness constraint and is implicitly many-to-one:

class SourceStar(db.Model):
__tablename__ = "source_stars"
id = Column("id", Integer, primary_key=True)
source_id = Column("source_id", Integer, ForeignKey("sources.id"))

Two "star source" operations for source s could race and each result in a separate SourceStar(source_id=s.id) record, which would cause subsequent one_or_none() queries to raise MultipleResultsFound.


Summarized from findings by Claude while investigating other data races. It's not obvious to me from GitHub history why SourceStar is a separate model rather than a Boolean attribute on Source itself, but that's a bigger refactoring than just making sure there is exactly either zero or one of them for a given source.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions