Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1652] [Regression] [main/1.4] Failure to raise initialization exception #6434

Closed
2 tasks done
jtcohen6 opened this issue Dec 13, 2022 · 5 comments · Fixed by #6447
Closed
2 tasks done

[CT-1652] [Regression] [main/1.4] Failure to raise initialization exception #6434

jtcohen6 opened this issue Dec 13, 2022 · 5 comments · Fixed by #6447
Labels
bug Something isn't working logging regression
Milestone

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Dec 13, 2022

Is this a regression in a recent version of dbt-core?

  • I believe this is a regression in dbt-core functionality
  • I have searched the existing issues, and I could not find an existing issue for this regression

Current Behavior

If I run dbt with a profile that expects an adapter to be installed, and the adapter is not in fact installed, I do not see any error from dbt run:

$ dbt run

(no output)

$ dbt --debug run
$ echo $?
2

(no other output)

I do see the expected error from dbt debug:

$ dbt debug
15:46:40  Running with dbt=1.4.0-a1
dbt version: 1.4.0-a1
python version: 3.10.9
python path: /Users/jerco/dev/product/dbt-core/env/bin/python3
os info: macOS-12.4-arm64-arm-64bit
Using profiles.yml file at /Users/jerco/.dbt/profiles.yml
Using dbt_project.yml file at /Users/jerco/dev/scratch/testy/dbt_project.yml

15:46:40  Error importing adapter: No module named 'dbt.adapters.bigquery'
Configuration:
  profiles.yml file [ERROR invalid]
  dbt_project.yml file [OK found and valid]

Required dependencies:
 - git [OK found]

1 check failed:
Profile loading failed for the following reason:
Runtime Error
  Credentials in profile "sandbox-bigquery", target "dev" invalid: Runtime Error
    Could not find adapter type bigquery!

Expected/Previous Behavior

dbt run should raise the same error as dbt debug, if there is an error during initialization (e.g. trying to use an uninstalled adapter)

Steps To Reproduce

  1. Install dbt from the main branch
  2. Specify a profile that requires an adapter that isn't installed
  3. dbt run

Relevant log output

No response

Environment

- OS: macOS 12.4
- Python: Python 3.10.9
- dbt (working version): 1.3
- dbt (regression version): 1.4.0-a1

Which database adapter are you using with dbt?

No response

Additional Context

No response

@jtcohen6 jtcohen6 added bug Something isn't working triage regression labels Dec 13, 2022
@jtcohen6 jtcohen6 added this to the v1.4 milestone Dec 13, 2022
@github-actions github-actions bot changed the title [Regression] [main/1.4] Failure to raise initialization exception [CT-1652] [Regression] [main/1.4] Failure to raise initialization exception Dec 13, 2022
@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Dec 13, 2022

If I drop a breakpoint here (line 197):

dbt-core/core/dbt/main.py

Lines 196 to 198 in 83b1fee

with adapter_management():
task, res = run_from_args(parsed)

On main branch:

ipdb> task, res = run_from_args(parsed)
*** dbt.exceptions.RuntimeException: Runtime Error
  Could not run dbt

On 1.3.latest branch:

ipdb> task, res = run_from_args(parsed)
15:59:14  Error importing adapter: No module named 'dbt.adapters.bigquery'
15:59:14  Encountered an error while reading profiles:
15:59:14    ERROR: Runtime Error
  Credentials in profile "sandbox-bigquery", target "dev" invalid: Runtime Error
    Could not find adapter type bigquery!
15:59:14  Defined profiles:
15:59:14   - sandbox-bigquery
15:59:14   - sandbox-databricks
15:59:14   - demo_data
15:59:14   - garage-spark
15:59:14   - garage-firebolt
15:59:14   - garage-postgres
15:59:14   - garage-snowflake
15:59:14   - integration_tests
15:59:14   - jaffle_shop
15:59:14   - sandbox-galaxy
15:59:14   - sandbox-redshift
15:59:14   - sandbox-snowflake
15:59:14
For more information on configuring profiles, please consult the dbt docs:

https://docs.getdbt.com/docs/configure-your-profile

*** dbt.exceptions.RuntimeException: Runtime Error
  Could not run dbt

@jtcohen6
Copy link
Contributor Author

The exception is occurring on this line:

dbt-core/core/dbt/main.py

Lines 223 to 225 in 83b1fee

# this will convert DbtConfigErrors into RuntimeExceptions
# task could be any one of the task objects
task = parsed.cls.from_args(args=parsed)

The profile config error is being appropriately caught & handled here:

except dbt.exceptions.DbtProfileError as exc:
fire_event(DbtProfileError())
fire_event(DbtProfileErrorException(exc=str(exc)))
all_profiles = read_profiles(flags.PROFILES_DIR).keys()
if len(all_profiles) > 0:
fire_event(ProfileListTitle())
for profile in all_profiles:
fire_event(ListSingleProfile(profile=profile))
else:
fire_event(NoDefinedProfiles())
fire_event(ProfileHelpMessage())
tracking.track_invalid_invocation(args=args, result_type=exc.result_type)
raise dbt.exceptions.RuntimeException("Could not run dbt") from exc

But we're not doing any logging, or bubbling up the RuntimeException, as we were in previous versions.

@jtcohen6
Copy link
Contributor Author

I think this change is due to a change from #6291:

# The default event manager will not log anything, but some tests run code that
# generates events, without configuring the event manager.
EVENT_MANAGER: EventManager = EventManager()

The codepath with the exception is being executed before we've called setup_event_logger. Previously, if we fired events before setup_event_logger had been called, they would go to a simple stdout logger. That one used defaults that didn't respect user-supplied configuration... but still, better than not seeing these logs/exceptions at all!

@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Dec 13, 2022

Potential fix: initialize a "basic" EventManager, which then gets replaced as soon as we make it to the real setup_event_logger. This ensures that, if we run into an initialization error before then, any associated events (including exceptions / tracebacks) aren't swallowed.

Illustrative code in this commit: 9393513

Using the changes in that commit:

$ dbt run
16:30:50  Error importing adapter: No module named 'dbt.adapters.bigquery'
16:30:50  Encountered an error while reading profiles:
16:30:50    ERROR: Runtime Error
  Credentials in profile "sandbox-bigquery", target "dev" invalid: Runtime Error
    Could not find adapter type bigquery!
16:30:50  Defined profiles:
16:30:50   - sandbox-bigquery
16:30:50   - sandbox-databricks
16:30:50   - demo_data
16:30:50   - garage-spark
16:30:50   - garage-firebolt
16:30:50   - garage-postgres
16:30:50   - garage-snowflake
16:30:50   - integration_tests
16:30:50   - jaffle_shop
16:30:50   - sandbox-galaxy
16:30:50   - sandbox-redshift
16:30:50   - sandbox-snowflake
16:30:50
For more information on configuring profiles, please consult the dbt docs:

https://docs.getdbt.com/docs/configure-your-profile

16:30:50  Encountered an error:
Runtime Error
  Could not run dbt

@jtcohen6
Copy link
Contributor Author

jtcohen6 commented Jan 3, 2023

Resolved by #6447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logging regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant