Skip to content

Commit

Permalink
Added lazy load to prevent multiplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch committed Dec 19, 2024
1 parent 1b866a7 commit edc17a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ async def root():
app,
host="0.0.0.0",
port=8888,
log_config=DEFAULT_LOGGING,
# log_config=DEFAULT_LOGGING,
) # type: ignore
12 changes: 10 additions & 2 deletions app/repository/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sqlalchemy import desc, func, or_
from sqlalchemy import update as db_update
from sqlalchemy.exc import NoResultFound, OperationalError
from sqlalchemy.orm import Query, Session
from sqlalchemy.orm import Query, Session, lazyload
from sqlalchemy_utils import escape_like

from app.errors import RepositoryError
Expand Down Expand Up @@ -66,7 +66,7 @@ def _get_query(db: Session) -> Query:
.subquery()
)

return (
query = (
db.query(
Family,
geography_subquery.c.geography_ids,
Expand All @@ -92,7 +92,15 @@ def _get_query(db: Session) -> Query:
Corpus.import_id,
Organisation,
)
.options(
# Disable any default eager loading as this was causing multiplicity due to
# implicit joins in relationships on the selected models.
lazyload("*")
)
)
_LOGGER.error(query)

return query


def _family_to_dto(
Expand Down

0 comments on commit edc17a7

Please sign in to comment.