From 3e8d389e65a67bad0ae467761c4a4519507e367d Mon Sep 17 00:00:00 2001 From: Matthew McKnight <91097623+McKnight-42@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:08:24 -0500 Subject: [PATCH] a slight rework of 955 to keep a seperation of concerns (#957) * a slight rework of 955 to keep a seperation of concerns * move query_header back into inital if, save assignement for truthy, else return empty dict --- dbt/adapters/bigquery/connections.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dbt/adapters/bigquery/connections.py b/dbt/adapters/bigquery/connections.py index 1e96ed5ef..ff544f0d0 100644 --- a/dbt/adapters/bigquery/connections.py +++ b/dbt/adapters/bigquery/connections.py @@ -435,6 +435,18 @@ def get_table_from_response(cls, resp): column_names = [field.name for field in resp.schema] return agate_helper.table_from_data_flat(resp, column_names) + def get_labels_from_query_comment(cls): + if ( + hasattr(cls.profile, "query_comment") + and cls.profile.query_comment + and cls.profile.query_comment.job_label + and cls.query_header + ): + query_comment = cls.query_header.comment.query_comment + return cls._labels_from_query_comment(query_comment) + + return {} + def raw_execute( self, sql, @@ -447,16 +459,7 @@ def raw_execute( fire_event(SQLQuery(conn_name=conn.name, sql=sql, node_info=get_node_info())) - if ( - hasattr(self.profile, "query_comment") - and self.profile.query_comment - and self.profile.query_comment.job_label - and self.query_header - and (query_comment := self.query_header.comment.query_comment) - ): - labels = self._labels_from_query_comment(query_comment) - else: - labels = {} + labels = self.get_labels_from_query_comment() if active_user: labels["dbt_invocation_id"] = active_user.invocation_id