From 6e58c764f75dc266463d98be4152f69daaadf64c Mon Sep 17 00:00:00 2001 From: "Parker J. Rule" Date: Thu, 27 Apr 2023 13:07:14 -0400 Subject: [PATCH] Demo: handle missing plans table, disable graph areas --- gerrydb/repos/view.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/gerrydb/repos/view.py b/gerrydb/repos/view.py index 9ba8b82..7261688 100644 --- a/gerrydb/repos/view.py +++ b/gerrydb/repos/view.py @@ -165,29 +165,33 @@ def to_graph(self, plans: bool = True, geometry: bool = False) -> nx.Graph: prefixed_columns = [f"{self.path}.{col}" for col in columns] join_clauses = [ - ( - "JOIN gerrydb_graph_node_area ON " - f"{self.path}.path = gerrydb_graph_node_area.path" - ) + # ( + # "JOIN gerrydb_graph_node_area ON " + # f"{self.path}.path = gerrydb_graph_node_area.path" + # ) ] - columns.append("area") - prefixed_columns.append("gerrydb_graph_node_area.area") + # columns.append("area") + # prefixed_columns.append("gerrydb_graph_node_area.area") if plans: # Join plan assignment columns. - raw_plan_cols = self._conn.execute( - "SELECT name from pragma_table_info('gerrydb_plan_assignment')", - ).fetchall() + try: + raw_plan_cols = self._conn.execute( + "SELECT name from pragma_table_info('gerrydb_plan_assignment')", + ).fetchall() + join_clauses.append( + "JOIN gerrydb_plan_assignment " + f"ON {self.path}.path = gerrydb_plan_assignment.path" + ) + except sqlite3.OperationalError: + # No plans table. + raw_plan_cols = [] plan_columns = [row[0] for row in raw_plan_cols] columns += plan_columns prefixed_columns += [ f"gerrydb_plan_assignment.{col}" for col in plan_columns ] - join_clauses.append( - "JOIN gerrydb_plan_assignment " - f"ON {self.path}.path = gerrydb_plan_assignment.path" - ) if geometry: # Join geographic layers: add internal points.