Skip to content

bug(thesis): Thesis.__str__ causes N+1 queries via authors.all() #313

Description

@thejoeejoee

Description

Thesis.__str__() in django/apps/thesis/models/thesis.py calls self.authors.all(), which fires a database query every time the thesis is converted to a string.

def __str__(self):
    return '{}: {}'.format(', '.join(str(a) for a in self.authors.all()), self.title)

In admin views, logging, serializer __repr__, or anywhere theses are listed, this creates an N+1 query problem — one extra query per thesis instance.

Severity

Medium — performance degradation, especially in admin and logging contexts.

Location

django/apps/thesis/models/thesis.py__str__()

Fix

Either cache the author names on the model, use prefetch_related('authors') consistently, or simplify __str__ to not require the relation (e.g., use self.title only).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingimpact: mediumMedium impact — correctness or performance issuepythonPull requests that update Python code

    Type

    No type

    Fields

    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