File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 23
23
from sqlalchemy .dialects .postgresql import UUID
24
24
from sqlalchemy .exc import IntegrityError , OperationalError
25
25
from sqlalchemy .ext .declarative import declarative_base # type: ignore
26
- from sqlalchemy .orm import sessionmaker
26
+ from sqlalchemy .orm import Session as BaseSession , raiseload , sessionmaker
27
27
28
28
from warehouse .metrics import IMetricsService
29
29
from warehouse .utils .attrs import make_repr
@@ -92,10 +92,18 @@ class Model(ModelBase):
92
92
)
93
93
94
94
95
+ # Custom Session to prevent lazy-loading
96
+ class StrictSession (BaseSession ):
97
+ def query (self , * entities , ** kwargs ):
98
+ query = super ().query (* entities )
99
+ query = query .options (raiseload ("*" ))
100
+ return query
101
+
102
+
95
103
# Create our session class here, this will stay stateless as we'll bind the
96
104
# engine to each new state we create instead of binding it to the session
97
105
# class.
98
- Session = sessionmaker ()
106
+ Session = sessionmaker (class_ = StrictSession )
99
107
100
108
101
109
def listens_for (target , identifier , * args , ** kwargs ):
You can’t perform that action at this time.
0 commit comments