Skip to content

Commit

Permalink
Use raiseload in query loading options
Browse files Browse the repository at this point in the history
Use [raiseload](https://docs.sqlalchemy.org/en/14/orm/loading_relationships.html#sqlalchemy.orm.raiseload) loading technique in query options
to raise an error on accessing attributes that haven't been eagerly
loaded. There have been suboptimal SQL queries in sir previously due to
missing columns in extrapaths or using hybrid attributes in fields or
extrapaths which caused lazy loading. Since the attributes we access in
SIR are fixed and remain the same, we should aim for loading all of those
eagerly. raiseload will raise an error with a stacktrace to help us fix
the issue if a lazy load happens, helping in performance debugging.
  • Loading branch information
amCap1712 committed Nov 7, 2022
1 parent 17a8340 commit 14db7a1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sir/schema/searchentities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from xml.etree.cElementTree import tostring
except ImportError:
from xml.etree.ElementTree import tostring
from sqlalchemy.orm import class_mapper, Load
from sqlalchemy.orm import class_mapper, Load, raiseload
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.orm.descriptor_props import CompositeProperty
from sqlalchemy.orm.interfaces import ONETOMANY, MANYTOONE
Expand Down Expand Up @@ -229,7 +229,7 @@ def build_entity_query(self):
load = defer_everything_but(class_mapper(model),
load,
*required_columns)
query = query.options(load)
query = query.options(load, raiseload("*"))
if self.extraquery is not None:
query = self.extraquery(query)
return query
Expand Down

0 comments on commit 14db7a1

Please sign in to comment.