Skip to content

Commit 17a374c

Browse files
authored
Fix "Can't determine which FROM clause to join from" SQLAlchemy error (#38)
Something changed in SQLAlchemy 1.3 after we upgraded (maybe in 5b02472?) which caused the graph and matrix queries to start erroring, showing something like: > InvalidRequestError("Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Please use the .select_from() method to establish an explicit left side, as well as providing an explcit ON clause if not present already to help resolve the ambiguity.") This fixes the errors by explicitly specifying which table to use as the FROM query. From what I understand we only have this error if there are multiple joins in the same query. The query in load_geomean_data also seemed to be missing a join on the samples table. I guess SQLAlchemy must have previously inferred the join or something? Since the relations go run -> sample -> test. This affected both the sqlite and postgres backends, and I've tested this fixes the error with both.
1 parent 1bdfa48 commit 17a374c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lnt/server/ui/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ def load_graph_data(plot_parameter, show_failures, limit, xaxis_date, revision_c
881881
# we want to load. Actually, we should just make this a single query.
882882
values = session.query(plot_parameter.field.column, ts.Order,
883883
ts.Run.start_time, ts.Run.id) \
884+
.select_from(ts.Sample) \
884885
.join(ts.Run).join(ts.Order) \
885886
.filter(ts.Run.machine_id == plot_parameter.machine.id) \
886887
.filter(ts.Sample.test == plot_parameter.test) \
@@ -924,6 +925,7 @@ def load_geomean_data(field, machine, limit, xaxis_date, revision_cache=None):
924925
values = session.query(sqlalchemy.sql.func.min(field.column),
925926
ts.Order,
926927
sqlalchemy.sql.func.min(ts.Run.start_time)) \
928+
.select_from(ts.Sample) \
927929
.join(ts.Run).join(ts.Order).join(ts.Test) \
928930
.filter(ts.Run.machine_id == machine.id) \
929931
.filter(field.column.isnot(None)) \
@@ -1105,6 +1107,7 @@ def v4_graph():
11051107
q_baseline = session.query(req.field.column,
11061108
ts.Order.llvm_project_revision,
11071109
ts.Run.start_time, ts.Machine.name) \
1110+
.select_from(ts.Sample) \
11081111
.join(ts.Run).join(ts.Order).join(ts.Machine) \
11091112
.filter(ts.Run.id == baseline.id) \
11101113
.filter(ts.Sample.test == req.test) \
@@ -1900,6 +1903,7 @@ def v4_matrix():
19001903
for req in plot_parameters:
19011904
q = session.query(req.field.column, ts.Order.llvm_project_revision,
19021905
ts.Order.id) \
1906+
.select_from(ts.Sample) \
19031907
.join(ts.Run) \
19041908
.join(ts.Order) \
19051909
.filter(ts.Run.machine_id == req.machine.id) \
@@ -1936,6 +1940,7 @@ def v4_matrix():
19361940
q_baseline = session.query(req.field.column,
19371941
ts.Order.llvm_project_revision,
19381942
ts.Order.id) \
1943+
.select_from(ts.Sample) \
19391944
.join(ts.Run) \
19401945
.join(ts.Order) \
19411946
.filter(ts.Run.machine_id == req.machine.id) \

0 commit comments

Comments
 (0)