Repository: dbt-labs/dbt-core

Issue:
'NoneType' object has no attribute 'job_label'
I am trying to configure the bigquery connection profile. Somehow get the following error message after "dbt debug". 

>'NoneType' object has no attribute 'job_label'

Not sure how to debug this. Can someone give me a hint please?
![image](https://user-images.githubusercontent.com/14008800/116947235-4d994f00-acd0-11eb-8eda-171b4fb638f4.png)



Discussion:
Hey @QPeiran, what version of dbt are you using? Are you able to run `dbt --version`?
Hi @jtcohen6 , the version I am using is 0.19.0
![image](https://user-images.githubusercontent.com/14008800/116951810-ffd71380-acdc-11eb-92f9-069849efc3fd.png)

@QPeiran Ok, I appreciate you sharing that info. I'm not sure what's going on here. Could you try running a different command with debug-level logging:
```
$ dbt --debug run
```
Hopefully, this will print out a more detailed stacktrace, including a hint as to where the `'NoneType' object has no attribute 'job_label'` message originates.
Hi @jtcohen6 , thank you for looking into this problem.
Here's the full log after `--debug run`:
```
2021-05-04 23:54:01.563985 (MainThread): Running with dbt=0.19.0
2021-05-04 23:54:02.396733 (MainThread): running dbt with arguments Namespace(record_timing_info=None, debug=True, log_format='default', write_json=True, use_colors=None, strict=False, warn_error=False, partial_parse=None, single_threaded=False, test_new_parser=False, project_dir=None, profiles_dir='C:\\Users\\PeiranQ\\.dbt', profile=None, target=None, vars='{}', log_cache_events=False, use_cache=True, fail_fast=False, threads=None, version_check=True, models=None, exclude=None, selector_name=None, state=None, defer=None, full_refresh=False, cls=<class 'dbt.task.run.RunTask'>, which='run', rpc_method='run')
2021-05-04 23:54:02.396733 (MainThread): Tracking: tracking
2021-05-04 23:54:02.411176 (MainThread): Sending event: {'category': 'dbt', 'action': 'invocation', 'label': 'start', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AC595760>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE167CA0>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE167A00>]}
2021-05-04 23:54:02.439673 (MainThread): Partial parsing not enabled
2021-05-04 23:54:02.468677 (MainThread): Parsing macros\adapters.sql
2021-05-04 23:54:02.522676 (MainThread): Parsing macros\catalog.sql
2021-05-04 23:54:02.532678 (MainThread): Parsing macros\etc.sql
2021-05-04 23:54:02.535681 (MainThread): Parsing macros\materializations\copy.sql
2021-05-04 23:54:02.541678 (MainThread): Parsing macros\materializations\incremental.sql
2021-05-04 23:54:02.555679 (MainThread): Parsing macros\materializations\seed.sql    
2021-05-04 23:54:02.558679 (MainThread): Parsing macros\materializations\snapshot.sql
2021-05-04 23:54:02.560682 (MainThread): Parsing macros\materializations\table.sql   
2021-05-04 23:54:02.581678 (MainThread): Parsing macros\materializations\view.sql
2021-05-04 23:54:02.586681 (MainThread): Parsing macros\core.sql
2021-05-04 23:54:02.594678 (MainThread): Parsing macros\adapters\common.sql
2021-05-04 23:54:02.775685 (MainThread): Parsing macros\etc\datetime.sql
2021-05-04 23:54:02.785679 (MainThread): Parsing macros\etc\get_custom_alias.sql   
2021-05-04 23:54:02.786680 (MainThread): Parsing macros\etc\get_custom_database.sql
2021-05-04 23:54:02.788680 (MainThread): Parsing macros\etc\get_custom_schema.sql  
2021-05-04 23:54:02.792685 (MainThread): Parsing macros\etc\is_incremental.sql      
2021-05-04 23:54:02.794679 (MainThread): Parsing macros\etc\query.sql
2021-05-04 23:54:02.795683 (MainThread): Parsing macros\materializations\helpers.sql
2021-05-04 23:54:02.846685 (MainThread): Parsing macros\materializations\test.sql
2021-05-04 23:54:02.847684 (MainThread): Parsing macros\materializations\common\merge.sql
2021-05-04 23:54:02.865682 (MainThread): Parsing macros\materializations\incremental\helpers.sql    
2021-05-04 23:54:02.868681 (MainThread): Parsing macros\materializations\incremental\incremental.sql
2021-05-04 23:54:02.877681 (MainThread): Parsing macros\materializations\seed\seed.sql
2021-05-04 23:54:02.958683 (MainThread): Parsing macros\materializations\snapshot\snapshot.sql
2021-05-04 23:54:03.065685 (MainThread): Parsing macros\materializations\snapshot\snapshot_merge.sql
2021-05-04 23:54:03.069684 (MainThread): Parsing macros\materializations\snapshot\strategies.sql
2021-05-04 23:54:03.094684 (MainThread): Parsing macros\materializations\table\table.sql
2021-05-04 23:54:03.104685 (MainThread): Parsing macros\materializations\view\create_or_replace_view.sql
2021-05-04 23:54:03.160685 (MainThread): Parsing macros\materializations\view\view.sql
2021-05-04 23:54:03.188686 (MainThread): Parsing macros\schema_tests\accepted_values.sql
2021-05-04 23:54:03.194689 (MainThread): Parsing macros\schema_tests\not_null.sql
2021-05-04 23:54:03.196688 (MainThread): Parsing macros\schema_tests\relationships.sql
2021-05-04 23:54:03.199685 (MainThread): Parsing macros\schema_tests\unique.sql
2021-05-04 23:54:03.597695 (MainThread): Acquiring new bigquery connection "model.shop_Peiran.my_first_dbt_model".
2021-05-04 23:54:03.622020 (MainThread): Acquiring new bigquery connection "model.shop_Peiran.my_second_dbt_model".
2021-05-04 23:54:03.801025 (MainThread): Sending event: {'category': 'dbt', 'action': 'load_project', 'label': 'c7ccb26c-0fd4-4ee3-975e-208bbddcd51b', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE111670>]}
2021-05-04 23:54:03.843023 (MainThread): Sending event: {'category': 'dbt', 'action': 'resource_counts', 'label': 'c7ccb26c-0fd4-4ee3-975e-208bbddcd51b', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE25D550>]}
2021-05-04 23:54:03.852024 (MainThread): Found 2 models, 4 tests, 0 snapshots, 0 analyses, 161 macros, 0 operations, 0 seed files, 0 sources, 0 exposures
2021-05-04 23:54:03.864023 (MainThread):
2021-05-04 23:54:03.867023 (MainThread): Acquiring new bigquery connection "master".
2021-05-04 23:54:03.869023 (ThreadPoolExecutor-0_0): Acquiring new bigquery connection "list_dbt-bq".
2021-05-04 23:54:03.870024 (ThreadPoolExecutor-0_0): Opening a new connection, currently in state init
2021-05-04 23:54:08.116610 (ThreadPoolExecutor-1_0): Acquiring new bigquery connection "list_dbt-bq_dbt_peiran".
2021-05-04 23:54:08.116610 (ThreadPoolExecutor-1_0): Opening a new connection, currently in state init
2021-05-04 23:54:12.157205 (MainThread): 11:54:12 | Concurrency: 1 threads (target='dev')
2021-05-04 23:54:12.158205 (MainThread): 11:54:12 | 
2021-05-04 23:54:12.162203 (Thread-1): Began running node model.shop_Peiran.my_first_dbt_model
2021-05-04 23:54:12.163205 (Thread-1): 11:54:12 | 1 of 2 START table model dbt_peiran.my_first_dbt_model............... [RUN]
2021-05-04 23:54:12.164206 (Thread-1): Acquiring new bigquery connection "model.shop_Peiran.my_first_dbt_model".
2021-05-04 23:54:12.165208 (Thread-1): Compiling model.shop_Peiran.my_first_dbt_model
2021-05-04 23:54:12.168212 (Thread-1): Writing injected SQL for node "model.shop_Peiran.my_first_dbt_model"
2021-05-04 23:54:12.258208 (Thread-1): Opening a new connection, currently in state init
2021-05-04 23:54:16.225269 (Thread-1): Writing runtime SQL for node "model.shop_Peiran.my_first_dbt_model"
2021-05-04 23:54:16.240896 (Thread-1): On model.shop_Peiran.my_first_dbt_model: /* {"app": "dbt", "dbt_version": "0.19.0", "profile_name": "shop_Peiran", "target_name": "dev", "node_id": "model.shop_Peiran.my_first_dbt_model"} */


  create or replace table `dbt-bq`.`dbt_peiran`.`my_first_dbt_model`


  OPTIONS()
  as (
    /*
    Welcome to your first dbt model!
    Did you know that you can also configure models directly within SQL files?
    This will override configurations stated in dbt_project.yml

    Try changing "table" to "view" below
*/



with source_data as (

    select 1 as id
    union all
    select null as id

)

select *
from source_data

/*
    Uncomment the line below to remove records with null `id` values
*/

-- where id is not null
  );

2021-05-04 23:54:20.473153 (Thread-1): Sending event: {'category': 'dbt', 'action': 'run_model', 'label': 'c7ccb26c-0fd4-4ee3-975e-208bbddcd51b', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE2BCEB0>]}
2021-05-04 23:54:20.474150 (Thread-1): 11:54:20 | 1 of 2 OK created table model dbt_peiran.my_first_dbt_model.......... [CREATE TABLE (2.0 rows, 0.0 Bytes processed) in 8.31s]
2021-05-04 23:54:20.475151 (Thread-1): Finished running node model.shop_Peiran.my_first_dbt_model
2021-05-04 23:54:20.476151 (Thread-1): Began running node model.shop_Peiran.my_second_dbt_model
2021-05-04 23:54:20.477154 (Thread-1): 11:54:20 | 2 of 2 START view model dbt_peiran.my_second_dbt_model............... [RUN]
2021-05-04 23:54:20.478150 (Thread-1): Acquiring new bigquery connection "model.shop_Peiran.my_second_dbt_model".
2021-05-04 23:54:20.478150 (Thread-1): Compiling model.shop_Peiran.my_second_dbt_model
2021-05-04 23:54:20.482152 (Thread-1): Writing injected SQL for node "model.shop_Peiran.my_second_dbt_model"
2021-05-04 23:54:20.523154 (Thread-1): Writing runtime SQL for node "model.shop_Peiran.my_second_dbt_model"
2021-05-04 23:54:20.525154 (Thread-1): Opening a new connection, currently in state closed
2021-05-04 23:54:20.532152 (Thread-1): On model.shop_Peiran.my_second_dbt_model: /* {"app": "dbt", "dbt_version": "0.19.0", "profile_name": "shop_Peiran", "target_name": "dev", "node_id": "model.shop_Peiran.my_second_dbt_model"} */


  create or replace view `dbt-bq`.`dbt_peiran`.`my_second_dbt_model`
  OPTIONS()
  as -- Use the `ref` function to select from other models

select *
from `dbt-bq`.`dbt_peiran`.`my_first_dbt_model`
where id = 1;


2021-05-04 23:54:25.131186 (Thread-1): Sending event: {'category': 'dbt', 'action': 'run_model', 'label': 'c7ccb26c-0fd4-4ee3-975e-208bbddcd51b', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE2BCEB0>]}
2021-05-04 23:54:25.131186 (Thread-1): 11:54:25 | 2 of 2 OK created view model dbt_peiran.my_second_dbt_model.......... [OK in 4.65s]
2021-05-04 23:54:25.131186 (Thread-1): Finished running node model.shop_Peiran.my_second_dbt_model
2021-05-04 23:54:25.135718 (MainThread): Acquiring new bigquery connection "master".
2021-05-04 23:54:25.136732 (MainThread): 11:54:25 |
2021-05-04 23:54:25.137732 (MainThread): 11:54:25 | Finished running 1 table model, 1 view model in 21.27s.
2021-05-04 23:54:25.138732 (MainThread): Connection 'master' was properly closed.
2021-05-04 23:54:25.138732 (MainThread): Connection 'list_dbt-bq' was properly closed.
2021-05-04 23:54:25.139732 (MainThread): Connection 'list_dbt-bq_dbt_peiran' was properly closed.
2021-05-04 23:54:25.139732 (MainThread): Connection 'model.shop_Peiran.my_second_dbt_model' was properly closed.
2021-05-04 23:54:25.217730 (MainThread): 
2021-05-04 23:54:25.225734 (MainThread): Completed successfully
2021-05-04 23:54:25.262730 (MainThread): 
Done. PASS=2 WARN=0 ERROR=0 SKIP=0 TOTAL=2
2021-05-04 23:54:25.295732 (MainThread): Sending event: {'category': 'dbt', 'action': 'invocation', 'label': 'end', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE1196A0>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE111670>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x000001A4AE25D4F0>]}
2021-05-04 23:54:25.299733 (MainThread): Flushing usage events
```
I can't see any error message from here but still get that `'NoneType' object has no attribute 'job_label'` when `dbt debug` 

Btw, I found by executing  `dbt --debug run`, both example models are created successfully within Bigquery.
Meanwhile, I tested against using the snowflake and there is no error with `dbt debug`

(the difference could be for bigquery I am using the credentials generated by GCP service account, whereas the snowflake is using the username and password)
I have the same error with bigquery and dbt 0.20.0b1, with project created from tutorial: https://docs.getdbt.com/tutorial/create-a-project-dbt-cli

```-> % dbt debug
Running with dbt=0.20.0-b1
dbt version: 0.20.0-b1
python version: 3.9.2
python path: /home/mobuchowski/tools/pyenv/versions/3.9.2/bin/python3.9
os info: Linux-5.11.0-16-generic-x86_64-with-glibc2.33
Using profiles.yml file at /home/mobuchowski/.dbt/profiles.yml
Using dbt_project.yml file at /home/mobuchowski/code/dbt-test/dbt_project.yml

Configuration:
  profiles.yml file [OK found and valid]
  dbt_project.yml file [OK found and valid]

Required dependencies:
 - git [OK found]

Connection:
  method: service-account
  database: speedy-vim-308516
  schema: dbt_alice
  location: EU
  priority: interactive
  timeout_seconds: 300
  maximum_bytes_billed: None
  Connection test: ERROR

dbt was unable to connect to the specified database.
The database returned the following error:

  >'NoneType' object has no attribute 'job_label'

Check your database credentials and try again. For more information, visit:
https://docs.getdbt.com/docs/configure-your-profile
```
Ah, this makes much more sense for `v0.20.0-b1`! We added a notion of `query_comment.job_label` in #3145.

In particular, I think it's the interaction between the debug task setting `query_comment` to `None`, and the `dbt-bigquery` connection expecting `query_comment` to be a dict with a property named `job_label`:

https://github.com/fishtown-analytics/dbt/blob/26fb58bd1b08218781b182918f5ed4dec3f735d9/core/dbt/task/debug.py#L65

https://github.com/fishtown-analytics/dbt/blob/26fb58bd1b08218781b182918f5ed4dec3f735d9/plugins/bigquery/dbt/adapters/bigquery/connections.py#L312
Yes, that makes sense. In particular, my shotgun debugging by inserting `query-comment` in random places in project and profile did not succeed :slightly_smiling_face:  

Resolving patch:
diff --git a/plugins/bigquery/dbt/adapters/bigquery/connections.py b/plugins/bigquery/dbt/adapters/bigquery/connections.py
--- a/plugins/bigquery/dbt/adapters/bigquery/connections.py
+++ b/plugins/bigquery/dbt/adapters/bigquery/connections.py
@@ -309,7 +309,7 @@ def raw_execute(self, sql, fetch=False, *, use_legacy_sql=False):
 
         logger.debug('On {}: {}', conn.name, sql)
 
-        if self.profile.query_comment.job_label:
+        if self.profile.query_comment and self.profile.query_comment.job_label:
             query_comment = self.query_header.comment.query_comment
             labels = self._labels_from_query_comment(query_comment)
         else:


Test patch:
diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py
--- a/test/integration/049_dbt_debug_test/test_debug.py
+++ b/test/integration/049_dbt_debug_test/test_debug.py
@@ -64,6 +64,11 @@ def test_postgres_ok(self):
         self.run_dbt(['debug'])
         self.assertNotIn('ERROR', self.capsys.readouterr().out)
 
+    @use_profile('bigquery')
+    def test_bigquery_ok(self):
+        self.run_dbt(['debug'])
+        self.assertNotIn('ERROR', self.capsys.readouterr().out)
+
     @use_profile('postgres')
     def test_postgres_nopass(self):
         self.run_dbt(['debug', '--target', 'nopass'], expect_pass=False)